标签:groupby clu import 类别 state index dom learn clust
#k-means聚类分析 数据标准化
zcdata=(cdata-cdata.mean())/cdata.std()
zcdata.head()
from sklearn.cluster import KMeans
kmodel=KMeans(n_clusters=4,n_jobs=4,max_iter=100,random_state=0)
kmodel.fit(zcdata)
kmodel.labels_
from pandas import Series
Series(kmodel.labels_).value_counts()
cdata_rst=pd.concat([cdata,Series(kmodel.labels_,index=cdata.index)],axis=1)
cdata_rst.head()
#命名最后列名称
cdata_rst.columns=list(cdata.columns)+[‘类别‘]
cdata_rst.head()
#按类别分组统计 R M F
cdata_rst.groupby(cdata_rst[‘类别‘]).mean()
标签:groupby clu import 类别 state index dom learn clust
原文地址:https://www.cnblogs.com/tiankong-blue/p/11623394.html