计算其他指标
除了准确率之外,我们也来计算这个新模型的 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(____)