<jupyter_start><jupyter_text>Gaussian Mixture ModelingOvercomes the limitations of k-means clustering by making soft assignments of the data points. A Gaussian mixture will almost always fit better than k-means: the clustering will mimic the data cloud better and with a smaller k. k-means is useful primarily because it’s very fast, so might be more easily fit to very large data sets with largish dimensions.<jupyter_code>data = pd.read_csv('Wine2.csv')
## scale the data

mms = MinMaxScaler()
data.loc[:, data.columns != 'class'] = mms.fit_transform(data.loc[:, data.columns != 'class'])
kmeans = KMeans(n_clusters= 3)
kmeans.fit(data.drop('class',axis=1))
# Create a colormap
plt.scatter(data['Alcohol'], data['Malic_acid'], c= data['class'], s=40)
plt.title('Actual Classification')
plt.show()
gmm = GMM(n_components=3).fit(data.drop('class',axis=1))
labels = gmm.predict(data.drop('class',axis=1))
plt.scatter(data['Alcohol'], data['Malic_acid'], c=labels, s=40)
plt.title('GMM Classification')
plt.show()
pd.crosstab(data['class'], labels, rownames=['Actual Result'], colnames=['Predicted Result'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14713656387665197, 'fraction_numerical': 0.00881057268722467, 'mean_word_length': 7.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '99668', 'license': 'MIT', 'n_tokens_mistral': 392, 'n_tokens_neox': 368, 'n_words': 105, 'path': 'Section 6/6.5.ipynb', 'repo_name': 'PacktPublishing/Scikit-learn-Recipes', 'size': '1135'}