Vertopal.com Untitled
Vertopal.com Untitled
import numpy as np
import matplotlib.pyplot as plt
import sklearn
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn
df = pd.read_csv('/content/Champo data clustering.csv')
df
# If you have more than 2 features, you may need to use dimensionality
reduction techniques like PCA first
if len(features.columns) >= 2:
plt.scatter(features.iloc[:, 0], features.iloc[:, 1],
c=df['cluster'], cmap='viridis')
plt.scatter(kmeans.cluster_centers_[:, 0],
kmeans.cluster_centers_[:, 1], s=300, c='black', marker='*',
label='Centroids')
plt.title('Clusters of customers')
plt.xlabel('Feature 1') # Replace with your actual feature name
plt.ylabel('Feature 2') # Replace with your actual feature name
plt.legend()
plt.grid()
plt.show()
Sum of QtyRequired Sum of TotalArea Sum of Amount DURRY
HANDLOOM \
0 2466 139.5900 1.854041e+05 1021
1445
1 131 2086.0000 6.247460e+03 0
0
2 18923 53625.6544 1.592080e+06 3585
0
3 624 202.8987 1.481116e+04 581
0
4 464 8451.5625 5.862686e+04 0
0
DOUBLE BACK JACQUARD HAND TUFTED HAND WOVEN KNOTTED GUN TUFTED
\
0 0 0 0 0 0 0
1 25 106 0 0 0 0
3 0 2 0 41 0 0
4 459 5 0 0 0 0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
# ... (Your existing code for data loading and preprocessing) ...