日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ML之K-means:基于DIY数据集利用K-means算法聚类(测试9种不同聚类中心的模型性能)

發布時間:2025/3/21 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ML之K-means:基于DIY数据集利用K-means算法聚类(测试9种不同聚类中心的模型性能) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ML之K-means:基于DIY數據集利用K-means算法聚類(測試9種不同聚類中心的模型性能)

?

?

?

?

目錄

輸出結果

設計思路

實現代碼


?

?

?

?

輸出結果

?

設計思路

  • 1、使用均勻分布函數隨機三個簇,每個簇周圍10個數據樣本。
  • 2、繪制30個數據樣本的分布圖像。
  • 3、測試9種不同聚類中心數量下,每種情況的聚類質量,并作圖。

?

實現代碼

import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import KMeans from scipy.spatial.distance import cdist#1、使用均勻分布函數隨機三個簇,每個簇周圍10個數據樣本。 cluster1 = np.random.uniform(0.5, 1.5, (2, 10)) cluster2 = np.random.uniform(5.5, 6.5, (2, 10)) cluster3 = np.random.uniform(3.0, 4.0, (2, 10))#2、繪制30個數據樣本的分布圖像。 X = np.hstack((cluster1, cluster2, cluster3)).T plt.scatter(X[:,0], X[:, 1]) plt.xlabel('x1') plt.ylabel('x2') plt.title('DIY data:30, Random 3 clusters(10 data samples around each cluster)') plt.show()#3、測試9種不同聚類中心數量下,每種情況的聚類質量,并作圖。 K = range(1, 10) meandistortions = []for k in K:kmeans = KMeans(n_clusters=k)kmeans.fit(X)meandistortions.append(sum(np.min(cdist(X, kmeans.cluster_centers_, 'euclidean'), axis=1))/X.shape[0])plt.plot(K, meandistortions, 'bx-') plt.xlabel('k') plt.ylabel('Average Dispersion') plt.title('K-means: Selecting k with the Elbow Method') plt.show()

?

?

總結

以上是生活随笔為你收集整理的ML之K-means:基于DIY数据集利用K-means算法聚类(测试9种不同聚类中心的模型性能)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。