现在在机器分类的时候总会出现错误,现在不知道该怎么办了
import pandas as pd
import numpy as np
#a=居民消费水平
#b=城镇居民消费水平
#c=农村居民消费水平
#d=年末总人口
#e=城镇人口
#f=乡村人口
#g=居民人均可支配收入
#h=城镇居民人均可支配收入
#i=农村居民人均可支配收入
#j=交通事故发生数
#k=机动车交通事故发生数(起)
#l=汽车交通事故发生数(起)
#m=摩托车交通事故发生数(起)
#n=拖拉机交通事故发生数(起)
#o=非机动车交通事故发生数(起)
#p=自行车交通事故发生数(起)
#q=行人乘车人交通事故发生数(起)
#r=其他交通事故发生数(起)
content = pd.read_csv(r"C:\Users\Lenovo\Desktop\20温文涛 崔凯鑫 万正鹏\年度数据 (6).csv",encoding='utf-8')
print(content.head())
```python
from sklearn import preprocessing
content_zscore=pd.DataFrame(preprocessing.scale(content),columns=content.columns)
print (content_zscore)
from sklearn.cluster import KMeans
model=KMeans(n_clusters=5,random_state=0)
print(model.fit(content_zscore))
```python
C:\Users\Lenovo\PycharmProjects\pythonProject1\venv\lib\site-packages\sklearn\cluster\_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning
warnings.warn(
KMeans(n_clusters=5, random_state=0)
Process finished with exit code 0
看起来就是1个warning(提示你高版本的一些细节变化,但不影响你当前代码),你的聚类应该已经完成了。
你可以使用拟合得到model了,比如你可以在代码尾部print一下model和它的属性试试
print(model)
print("聚类中心:", model.cluster_centers_)
print("聚类标签:", model.labels_)