카테고리 없음
군집화 실습 -붓꽃
루돌푸다요
2024. 3. 30. 21:29
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
iris_df = sns.load_dataset('iris')
iris.head(3)
iris_df.info()
sns.scatterplot(data = iris_df, x = 'sepa_length', y = 'sepal_width')
sns.scatterplot(data = iris_df, x = 'sepal_length', y='sepal_width', hue ='species')
iris_df2 = iris_df[['sepal_length', 'sepal_width', 'petal_length', 'petal_width']]
iris_Df2.head(3)
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters = 3, init = 'K-means++', max_iter = 300, random_state = 42)
kmeans.fit(iris_df2)
kmeans.labels_
iris_df2['taget'] = iris_df['species']
iris_df2['cluster'] = kmeans.labels_
iris_df2
plt.figure(figsize = (12,6))
pltsubplot(1,2,1)
sns.scatterplot(data = iris_df2, x = 'sepal_length', y = 'sepal_width', hue = 'target, plaette = 'viridis')
plt.title('Original')
plt.subplot(1,2,2)
sns.scatterplot(data = iris_df2, x = 'sepal_length', y = 'sepal_width', hue = 'cluster')
plt.title('Clustering')
plt.show()