Advertisement
deniswhite77

Untitled

Mar 10th, 2022
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn.cluster import KMeans
  3. import seaborn as sns
  4.  
  5. data_full = pd.read_csv('/datasets/cars_label.csv')
  6.  
  7. data = data_full.drop(columns=['brand'])
  8.  
  9. model = KMeans(n_clusters =3,random_state =12345)
  10. model.fit(data)
  11.  
  12. # Дополнительный слой для центроидов
  13. centroids = pd.DataFrame(model.cluster_centers_,columns = data.columns)
  14. data_full['label'] = model.labels_.astype(str)
  15. centroids['label'] = ['0 centroid', '1 centroid', '2 centroid']
  16. data_full = pd.concat([data_full, centroids], ignore_index= True)
  17.  
  18. # Построение графика
  19. pairgrid = sns.pairplot(data_full, hue='brand', diag_kind='hist')
  20. pairgrid.data = centroids
  21. pairgrid.map_offdiag(func=sns.scatterplot, s=200, marker='*', color='red')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement