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. How can I aggregate the confusion matrix and calculate the accuracy?
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. How can I aggregate the confusion matrix and calculate the accuracy?
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)