計算其他評估指標
除了準確率之外,我們也來計算這個新模型的 F1 分數,以更完整地掌握模型效能。
我們已經替你完成 70-30 的訓練/測試切分,且已匯入所有必要的模組。
本練習屬於課程
行銷分析:用 Python 預測客戶流失
練習說明
- 預測測試集的標籤。
- 列印 F1 分數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import f1_score
from sklearn.metrics import f1_score
# Instantiate the classifier
clf = RandomForestClassifier()
# Fit to the data
clf.fit(X_train, y_train)
# Predict the labels of the test set
y_pred = ____
# Print the F1 score
print(____)