Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn.cluster import KMeans
- import seaborn as sns
- data_full = pd.read_csv('/datasets/cars_label.csv')
- data = data_full.drop(columns=['brand'])
- model = KMeans(n_clusters =3,random_state =12345)
- model.fit(data)
- # Дополнительный слой для центроидов
- centroids = pd.DataFrame(model.cluster_centers_,columns = data.columns)
- data_full['label'] = model.labels_.astype(str)
- centroids['label'] = ['0 centroid', '1 centroid', '2 centroid']
- data_full = pd.concat([data_full, centroids], ignore_index= True)
- # Построение графика
- pairgrid = sns.pairplot(data_full, hue='brand', diag_kind='hist')
- pairgrid.data = centroids
- pairgrid.map_offdiag(func=sns.scatterplot, s=200, marker='*', color='red')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement