繪製平方誤差總和
現在你要為每個 k 的值繪製平方誤差總和,並判斷是否出現彎肘(elbow)。這有助於你推導建議使用的叢集數量。
平方誤差總和已從上一個練習載入為名為 sse 的字典。matplotlib.pyplot 已以 plt 載入,seaborn 以 sns 載入。
你可以在主控台中探索該字典。
本練習屬於課程
Python 的客群分群
練習說明
- 新增繪圖標題「The Elbow Method」。
- 新增 X 軸標籤「k」。
- 新增 Y 軸標籤「SSE」。
- 繪製字典中以鍵儲存的每個
k對應的 SSE 值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Add the plot title "The Elbow Method"
plt.____('The Elbow Method')
# Add X-axis label "k"
plt.____('____')
# Add Y-axis label "SSE"
plt.____('____')
# Plot SSE values for each key in the dictionary
sns.____(x=list(sse.____()), y=list(sse.____()))
plt.show()