import numpy as np import pandas as pd from matplotlib import pyplot as plt from sklearn.mixture import GaussianMixture from sklearn.cluster import KMeans data=pd.read_csv('knnvsempgm2.csv') print("Input Data and Shape") print(data.shape) data.head() f1=data['V1'].values f2=data['V2'].values x=np.array(list(zip(f1,f2))) print("X",x) print('Graph for whole dataset') plt.scatter(f1,f2,c='black',s=15) plt.show() km=KMeans(10,random_state=42) l=km.fit(x).predict(x) print("labels",l) c=km.cluster_centers_ print("centroids",c) plt.scatter(x[:,0],x[:,1],c=l,s=40,cmap='viridis'); print('graph using kmeans algorithm') plt.scatter(c[:,0],c[:,1],marker='*',s=200,c='#050505') plt.show() gmm=GaussianMixture(n_components=3).fit(x) l=gmm.predict(x) p=gmm.predict_proba(x) size=10*p.max(1)**3 print('graph using em algorithm') plt.scatter(x[:,0],x[:,1],c=l,s=size,cmap='viridis') plt.show()