客户价值分析-K均值聚类分析及结论

#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()

posted @ 2019-10-04 21:35  天天见和  阅读(671)  评论(0编辑  收藏  举报