简体   繁体   中英

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. The confusion matrix is generated 10 times for each model. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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