新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonkmeans聚類的使用
1、用kmeans分為五個聚類,每個聚類內(nèi)部的數(shù)據(jù)為一個list,五個list組成聚類中心。

k = 5 # 聚類中心數(shù) kmeans_model = KMeans(n_clusters=k, n_jobs=4, random_state=123) # 聚類中心數(shù),并行的CPU核的數(shù)量,隨機數(shù)種子 fit_kmeans = kmeans_model.fit(airline_scale) # 模型訓練 print(kmeans_model.cluster_centers_) # 查看聚類中心 print(kmeans_model.labels_) # 查看樣本的類別標簽
2、label顯示按照kmeans劃分之后每個數(shù)據(jù)屬于哪個聚類。
# 統(tǒng)計不同類別樣本的數(shù)目
r1 = pd.Series(kmeans_model.labels_).value_counts()
print('最終每個類別的數(shù)目為:\n', r1)
result = kmeans_model.predict([[1.5, 1.5, 1.5, 1.5, 1.5]])
print(result)
# 最終確定在五個參數(shù)都是1.5的情況下的用戶屬于類別1
3\r1顯示每個聚類內(nèi)部的元素個數(shù),同時測試一組特定特征值的數(shù)據(jù)會被分配到哪個組中。
以上就是python kmeans聚類的使用,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
分享標題:創(chuàng)新互聯(lián)Python教程:Pythonkmeans聚類的使用
URL鏈接:http://fisionsoft.com.cn/article/cosgjhj.html


咨詢
建站咨詢
