對均勻資料使用 Elbow 方法
在前一個練習中,你在具有清楚叢集的資料上建立了 elbow 圖。現在來看看,當資料點呈現均勻分佈時,elbow 圖會是什麼樣子。你可能會想先把資料點顯示出來,再進行本練習。
資料已存放在 pandas 的 DataFrame uniform_data 中。x_scaled 與 y_scaled 是各點標準化後的 X 與 Y 座標欄位名稱。
本練習屬於課程
Python 中的叢集分析
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
distortions = []
num_clusters = range(2, 7)
# Create a list of distortions from the kmeans function
for i in ____:
cluster_centers, distortion = ____
____.append(____)
# Create a DataFrame with two lists - number of clusters and distortions
elbow_plot = pd.DataFrame({'num_clusters': ____, 'distortions': ____})
# Creat a line plot of num_clusters and distortions
sns.____(x=____, y=____, data=____)
plt.xticks(num_clusters)
plt.show()