text_plain_output_1.png
from fcmeans import FCM

from sklearn.datasets import load_digits

from sklearn.metrics import adjusted_rand_score

from sklearn.preprocessing import minmax_scale

import numpy as np # linear algebra

digits = load_digits()

K = 10 # number of clusters

X = digits['data']
feature_names = digits['feature_names']
X = minmax_scale(X,feature_range=(0,1))
npixels = int(np.sqrt(X.shape[1]))

y = digits['target']
target_names = digits['target_names']

images = digits['images']
for i in range(1,101):
    ax = plt.subplot(10,10,i)
    ax.imshow(images[i],cmap='Greys')
    ax.axes.xaxis.set_visible(False)
    ax.axes.yaxis.set_visible(False)

fcm = FCM(n_clusters=K, m=1.1, max_iter=100, error=1e-09, random_state=911)
fcm.fit(X)
centers = fcm.centers
labels = fcm.predict(X)

print('ARI = {ari:.2}'.format(ari=adjusted_rand_score(y, labels)))