import pandas as pd
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
 
df_features = pd.read_csv(r'11111111.csv',encoding='gbk') # 读入数据
#print(df_features)
'利用SSE选择k'
SSE = []  # 存放每次结果的误差平方和
for k in range(1,9):
    estimator = KMeans(n_clusters=k)  # 构造聚类器
    estimator.fit(df_features[['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32']])
    SSE.append(estimator.inertia_) # estimator.inertia_获取聚类准则的总和
X = range(1,9)
plt.xlabel('k')
plt.ylabel('SSE')
plt.plot(X,SSE,'o-')
plt.show()

 

相关文章:

  • 2022-12-23
  • 2023-03-18
  • 2022-12-23
  • 2021-08-25
  • 2021-04-06
  • 2021-04-24
  • 2021-05-01
猜你喜欢
  • 2022-02-10
  • 2021-06-02
  • 2021-07-03
  • 2021-04-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案