Alaricy

Untitled

Sep 16th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn.cluster import KMeans
  3.  
  4. data = pd.read_csv('/datasets/segments.csv')
  5.  
  6. model = KMeans(n_clusters=3, random_state=12345)
  7. model.fit(data)
  8. centroids = pd.DataFrame(model.cluster_centers_, columns=data.columns)
  9.  
  10. print("Типичные пользователи сегментов для 3-х кластеров:")
  11. print(centroids.round())
  12.  
  13. model = KMeans(n_clusters=4, random_state=12345)
  14. model.fit(data)
  15. centroids = pd.DataFrame(model.cluster_centers_, columns=data.columns)
  16.  
  17. print("Типичные пользователи сегментов для 4-х кластеров:")
  18. print(centroids.round())
Add Comment
Please, Sign In to add comment