Random Forest Classifier-第 1 部分
現在來建立第一個用於詐欺偵測的隨機森林分類器。希望你能做得比剛剛計算出的基準準確率更好,該值約為 96%。這個模型會作為你在接下來練習中要改進的「基準」模型。先從將資料分成訓練集與測試集,以及定義 Random Forest 模型開始。可用的資料為特徵 X 與標籤 y。
本練習屬於課程
Fraud Detection in Python
練習說明
- 從
sklearn匯入隨機森林分類器。 - 將特徵
X與標籤y分割為訓練集與測試集,並將 30% 留作測試集。 - 將隨機森林分類器指定給
model,並將random_state維持在 5。這裡需要設定隨機種子,以便在不同模型之間比較結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the random forest model from sklearn
from sklearn.ensemble import ____
# Split your data into training and test set
X_train, X_test, y_train, y_test = ____(____, ____, test_size=____, random_state=0)
# Define the model as the random forest
model = ____(random_state=5)