Downloads · 30 days
0
mltrev23/kmeans-wine-clustering
kmeans-wine-clustering is a machine learning model from mltrev23. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains a K-Means clustering model trained on the mltrev23/wine-clustering dataset. The model is designed to group wines into clusters based on their chemical properties, helping to uncover underlying…
Downloads · 30 days
0
Access
Public
Updated Sep 4, 2024
Repo size
2.3 KB
Likes
0
Public
Click a slice to open those files.
.md4.3 KB · 53%
From the Hugging Face model README
This repository contains a K-Means clustering model trained on the mltrev23/wine-clustering dataset. The model is designed to group wines into clusters based on their chemical properties, helping to uncover underlying patterns and relationships within the data.
K clusters by minimizing the within-cluster variance. This algorithm is effective for identifying distinct groups in the dataset based on the input features.mltrev23/wine-clustering dataset.
Alcohol, Malic_Acid, Ash, Ash_Alcanity, Magnesium, Total_Phenols, Flavanoids, Nonflavanoid_Phenols, Proanthocyanins, Color_Intensity, Hue, OD280, and Proline.K): The optimal number of clusters was determined using the elbow method or silhouette analysis, resulting in K = [Insert optimal K] clusters.(Replace the placeholder [Insert optimal K] with the actual number of clusters.)
To run the model, you'll need the following Python libraries:
pip install pandas
pip install numpy
pip install scikit-learn
You can load the trained K-Means model using the following code snippet:
import joblib
# Load the trained model
model = joblib.load('wine_clustering_kmeans.model')
To assign new data points to the existing clusters, use the following code:
import pandas as pd
# Example input data (replace with your actual data)
data = pd.DataFrame({
'Alcohol': [14.23, 13.20],
'Malic_Acid': [1.71, 1.78],
'Ash': [2.43, 2.14],
'Ash_Alcanity': [15.6, 11.2],
'Magnesium': [127, 100],
'Total_Phenols': [2.80, 2.65],
'Flavanoids': [3.06, 2.76],
'Nonflavanoid_Phenols': [0.28, 0.26],
'Proanthocyanins': [2.29, 1.28],
'Color_Intensity': [5.64, 4.38],
'Hue': [1.04, 1.05],
'OD280': [3.92, 3.40],
'Proline': [1065, 1050]
})
# Predict the cluster for each wine sample
cluster_predictions = model.predict(data)
print(cluster_predictions)
You can evaluate the clustering model's performance by analyzing the characteristics of each cluster:
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
# Assuming you have a dataset and cluster assignments
pca = PCA(n_components=2)
reduced_data = pca.fit_transform(data)
plt.scatter(reduced_data[:, 0], reduced_data[:, 1], c=cluster_predictions)
plt.title("Wine Clusters")
plt.xlabel("PCA Component 1")
plt.ylabel("PCA Component 2")
plt.show()
To understand what differentiates each cluster:
import numpy as np
# Calculate the mean values of each feature for each cluster
cluster_centers = model.cluster_centers_
for i, center in enumerate(cluster_centers):
print(f"Cluster {i}:")
print({feature: value for feature, value in zip(data.columns, center)})
The K-Means model provides cluster centroids that can be analyzed to understand the typical properties of wines in each cluster. You can use these centroids to profile each cluster and derive insights about the wines grouped together.
If you use this model in your research or application, please cite the dataset and the following reference for K-Means clustering:
mltrev23/wine-clustering