開始使用免費開始

叢集的基本檢查

在 FIFA 18 資料集中,我們在前面的練習著重於後衛。這次改從球員的進攻屬性下手。速度(pac)、帶球(dri)與射門(sho)通常是偏重進攻的球員會突出的特徵。本題已先用這三個屬性的標準化數值對資料做了 k-means 分群。請對得到的叢集做一些基本檢查。

資料存放在 pandas 的 DataFrame fifa 中。標準化後的欄位名稱存在清單 scaled_features。叢集標籤則存於 cluster_labels 欄位。回想一下,pandas 的 .count().mean() 方法可以用來找出 DataFrame 中觀測值的數量與平均值。

本練習屬於課程

Python 中的叢集分析

檢視課程

練習說明

  • 先以欄位 cluster_labels 分組,列印各叢集的大小。
  • 列印各叢集中球員薪資的平均值。球員以歐元計價的薪資欄位名稱為 eur_wage

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Print the size of the clusters
print(fifa.____(____)['ID'].count())

# Print the mean value of wages in each cluster
print(fifa.____(____)['eur_wage'].____())
編輯並執行程式碼