from numpy import concatenate,column_stack,row_stack
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_blobs
X, y = make_blobs(n_samples=1000, centers=[[-1,-1], [0,0], [1,1]] ,cluster_std=[0.4, 0.2, 0.2], random_state =9)
plt.scatter(X[:, 0], X[:, 1], marker='o')
plt.show()
from sklearn.cluster import KMeans
y_pred = KMeans(n_clusters=3, random_state=9).fit_predict(X)
plt.scatter(X[:, 0], X[:, 1], c=y_pred)
plt.show()
from sklearn import metrics
print(metrics.calinski_harabaz_score(X, y_pred))
yy=np.array([y_pred])
un=np.hstack((X,yy.T))
print(un)
print('\n')
A_1=['0','0','0']
A_2=['1','1','1']
A_3=['2','2','2']
for i in range(yy.shape[1]):
if un[i][2]==0:
A_1=row_stack((A_1,un[i]))
elif un[i][2]==1:
A_2=row_stack((A_2,un[i]))
elif un[i][2]==2:
A_3=row_stack((A_3,un[i]))
print(A_1,'\n','A_1 have ',A_1.shape[0],'element')
print(A_2,'\n','A_2 have ',A_2.shape[0],'element')
print(A_3,'\n','A_3 have ',A_3.shape[0],'element')