開始使用免費開始

預測 App 的評分

在上一個練習中你已經探索過 Google apps 資料集,現在我們來建立即時能根據部分特徵來預測 App 評分的模型。

為了做到這點,你將使用 scikit-learnDecisionTreeRegressor。決策樹是許多集成模型(ensemble)的基礎元件,溫習它的運作方式,能幫助你在本課程中更順利地學習。

我們將以 MAE(mean absolute error,平均絕對誤差)作為評估指標。這個指標相當好解讀,因為它代表實際評分與預測評分之間絕對差值的平均。

所有需要的模組都已經幫你預先匯入。特徵與目標分別已放在變數 Xy

本練習屬於課程

Python 的 Ensemble 方法

檢視課程

練習說明

  • 使用 train_test_split()Xy 切分為訓練集與測試集。測試集比例使用 20%(0.2)。
  • 建立一個 DecisionTreeRegressor() 實例 reg_dt,並設定以下超參數:min_samples_leaf = 3min_samples_split = 9
  • 使用 .fit() 將此回歸器擬合到訓練集。
  • 使用 .predict() 預測測試集的標籤。

動手互動練習

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

# Split into train (80%) and test (20%) sets
X_train, X_test, y_train, y_test = ____(____, ____, ____, random_state=42)

# Instantiate the regressor
reg_dt = ____(____, ____, random_state=500)

# Fit to the training set
____

# Evaluate the performance of the model on the test set
y_pred = ____
print('MAE: {:.3f}'.format(mean_absolute_error(y_test, y_pred)))
編輯並執行程式碼