Skip to content

Instantly share code, notes, and snippets.

@aishwarya-singh25
Created October 25, 2019 08:28
Show Gist options
  • Save aishwarya-singh25/321dedb784e13cfe7370b46f507513d7 to your computer and use it in GitHub Desktop.
Save aishwarya-singh25/321dedb784e13cfe7370b46f507513d7 to your computer and use it in GitHub Desktop.
Gaussian Mixture Models Implementation
#training k-means model
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=4)
kmeans.fit(data)
#predictions from kmeans
pred = kmeans.predict(data)
frame = pd.DataFrame(data)
frame['cluster'] = pred
frame.columns = ['Weight', 'Height', 'cluster']
#plotting results
color=['blue','green','cyan', 'black']
for k in range(0,4):
data = frame[frame["cluster"]==k]
plt.scatter(data["Weight"],data["Height"],c=color[k])
plt.show()
import pandas as pd
data = pd.read_csv('Clustering_gmm.csv')
plt.figure(figsize=(7,7))
plt.scatter(data["Weight"],data["Height"])
plt.xlabel('Weight')
plt.ylabel('Height')
plt.title('Data Distribution')
plt.show()
import pandas as pd
data = pd.read_csv('Clustering_gmm.csv')
# training gaussian mixture model
from sklearn.mixture import GaussianMixture
gmm = GaussianMixture(n_components=4)
gmm.fit(data)
#predictions from gmm
labels = gmm.predict(data)
frame = pd.DataFrame(data)
frame['cluster'] = labels
frame.columns = ['Weight', 'Height', 'cluster']
color=['blue','green','cyan', 'black']
for k in range(0,4):
data = frame[frame["cluster"]==k]
plt.scatter(data["Weight"],data["Height"],c=color[k])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment