简体   繁体   English

应用分层 10 折交叉验证时,如何获取 python 中所有混淆矩阵的聚合

[英]How to get the aggregate of all the confusion matrix in python when Stratified 10 fold cross validation is applied

I am using 10-fold cross-validation and evaluating the model on the basis of accuracy and precision.我正在使用 10 折交叉验证并根据准确性和精度评估模型。 The confusion matrix is generated 10 times for each model.混淆矩阵为每个模型生成 10 次。 Can anyone please let me know how can I aggregate the confusion matrix and calculate the accuracy?任何人都可以让我知道如何聚合混淆矩阵并计算准确度?

Thanks!!谢谢!!

You can use cross_val_predict function as follows and use it result as confusion_matrix() argument.您可以按如下方式使用cross_val_predict函数并将其结果用作confusion_matrix() cross_val_predict confusion_matrix()参数。

from sklearn.metrics import confusion_matrix
from sklearn.model_selection import cross_val_predict

y_pred = cross_val_predict(clf, x, y, cv=5)
cm = confusion_matrix(y, y_pred)

You need to provide a bit more information about the format of the data you have!您需要提供更多有关您拥有的数据格式的信息!

If you're using tensorflow, you can refer this source如果您使用的是 tensorflow,则可以参考此来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM