Created
October 25, 2019 08:28
-
-
Save aishwarya-singh25/321dedb784e13cfe7370b46f507513d7 to your computer and use it in GitHub Desktop.
Gaussian Mixture Models Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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