套用 stacking 預測 App 評分
在這個練習中,你將開始打造第一個 Stacking 集成模型。你要使用的資料集是第 1 章用過的第一個資料集。回想一下,我們的目標是預測每個 App 的評分(1 到 5 分)。我們使用的輸入特徵包括:Reviews、Size、Installs、Type、Price,以及 Content Rating。
我們已經完成了「步驟 1:準備資料集」。它以 apps 提供給你。我們已清理所需特徵,並將遺漏值以 0 取代。
現在,你要進行「步驟 2:建立第一層估計器」。
本練習屬於課程
Python 的 Ensemble 方法
練習說明
- 建立並訓練一個決策樹分類器,設定:
min_samples_leaf: 3與min_samples_split: 9。 - 建立並訓練一個 5-近鄰分類器,使用:
algorithm: 'ball_tree'(以加快處理)。 - 在測試集上以 accuracy 分數評估各估計器的效能。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Build and fit a Decision Tree classifier
clf_dt = ____(____, ____, random_state=500)
clf_dt.____
# Build and fit a 5-nearest neighbors classifier using the 'Ball-Tree' algorithm
clf_knn = ____
clf_knn.____
# Evaluate the performance using the accuracy score
print('Decision Tree: {:0.4f}'.format(accuracy_score(____)))
print('5-Nearest Neighbors: {:0.4f}'.format(accuracy_score(____)))