Untitled

From Tinct Hamster, 3 Months ago, written in Plain Text, viewed 76 times.
URL http://codebin.org/view/06fe9965 Embed
Download Paste or View Raw
  1. import pandas as pd
  2. import numpy as np  # Add this line
  3. from sklearn.cluster import KMeans
  4. import seaborn as sns
  5. import warnings
  6. warnings.filterwarnings("ignore", category=RuntimeWarning)
  7.  
  8. data_full = pd.read_csv('/datasets/cars_label.csv')
  9.  
  10. data = data_full.drop(columns=['brand'])
  11.  
  12. # Обучение модели
  13. model = KMeans(n_clusters=3, random_state=12345)
  14. model.fit(data)
  15.  
  16. # Дополнительный слой для центроидов
  17. centroids = pd.DataFrame(model.cluster_centers_, columns=data.columns)
  18.  
  19. centroids['brand'] = ['0 centroid', '1 centroid', '2 centroid']
  20.  
  21. data_all= pd.concat([data_full, centroids], ignore_index=True)
  22.  
  23. pairgrid = sns.pairplot(data_full, hue='brand', vars=data.columns[:-1], diag_kind='hist')
  24.  

Reply to "Untitled"

Here you can reply to the paste above