小编Mul*_*loy的帖子

使用 cross_validate 生成混淆矩阵

我试图弄清楚如何使用 cross_validate 生成混淆矩阵。我可以使用迄今为止的代码打印出分数。

# Instantiating model
model = DecisionTreeClassifier()

#Scores
scoring = {'accuracy' : make_scorer(accuracy_score), 
           'precision' : make_scorer(precision_score),
           'recall' : make_scorer(recall_score), 
           'f1_score' : make_scorer(f1_score)}

# 10-fold cross validation
scores = cross_validate(model, X, y, cv=10, scoring=scoring)

print("Accuracy (Testing):  %0.2f (+/- %0.2f)" % (scores['test_accuracy'].mean(), scores['test_accuracy'].std() * 2))
print("Precision (Testing):  %0.2f (+/- %0.2f)" % (scores['test_precision'].mean(), scores['test_precision'].std() * 2))
print("Recall (Testing):  %0.2f (+/- %0.2f)" % (scores['test_recall'].mean(), scores['test_recall'].std() * 2))
print("F1-Score (Testing):  %0.2f (+/- %0.2f)" % (scores['test_f1_score'].mean(), scores['test_f1_score'].std() * 2))
Run Code Online (Sandbox Code Playgroud)

但我正在尝试将这些数据放入混淆矩阵中。我可以使用 cross_val_predict 制作混淆矩阵 -

y_train_pred …
Run Code Online (Sandbox Code Playgroud)

python machine-learning confusion-matrix scikit-learn cross-validation

3
推荐指数
1
解决办法
3958
查看次数