Untitled

From Sweet Crane, 7 Months ago, written in Plain Text, viewed 335 times.
URL http://codebin.org/view/36e3503b Embed
Download Paste or View Raw
  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. # Обучение модели
  10. model = KMeans(n_clusters=3, random_state=12345)
  11. model.fit(data)
  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. centroids['brand'] = 4
  17. #data_all = pd.concat([data_full, centroids], ignore_index=True)
  18.  
  19. # Построение графика
  20. pairgrid = sns.pairplot((data_full), hue='brand', diag_kind='hist')
  21. pairgrid.data = centroids
  22. pairgrid.map_offdiag(func=sns.scatterplot, s=200, marker='*', palette='flag')

Reply to "Untitled"

Here you can reply to the paste above