使用 entropy 作為衡量準則
在這個練習中,你將在 Wisconsin Breast Cancer 資料集上,使用 entropy 作為資訊衡量準則來訓練分類樹。你會使用資料集中全部 30 個特徵,資料已分割為 80% 訓練集與 20% 測試集。
X_train 以及標籤陣列 y_train 已經在你的工作區中可用。
本練習屬於課程
Machine Learning with Tree-Based Models in Python
練習說明
從
sklearn.tree匯入DecisionTreeClassifier。建立一個
DecisionTreeClassifier,命名為dt_entropy,將最大深度設為 8。將資訊衡量準則設定為
'entropy'。在訓練集上擬合
dt_entropy。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import DecisionTreeClassifier from sklearn.tree
from ____.____ import ____
# Instantiate dt_entropy, set 'entropy' as the information criterion
dt_entropy = ____(____=____, ____='____', random_state=1)
# Fit dt_entropy to the training set
____.____(____, ____)