I would like to know how to transform a confusion matrix from scikit learn to a dataframe.
I do not know if it feasible to mix all mc of the different models. Why I am asking is because of readability. I have to always print in the terminal and the copy the mc in an excel file and it is really demanding since I run the script multiple times depending on the parameters chosen.
models = {'Model_SVC': model1, 'Model_G_NB': model2, 'Model_LR': model3, 'Model_RF': model4, 'Model_KN': model5, 'Model_MLP': model6}
cv_splitter = KFold(n_splits=10, shuffle=False, random_state=None)
for model_name, model in models.items():
y_pred = cross_val_predict(model, features, ylabels, cv=cv_splitter)
print("Model: {}".format(model_name))
print("Accuracy: {}".format(accuracy_score(ylabels, y_pred)))
cm = confusion_matrix(ylabels, y_pred)
output = pd.DataFrame()
print("matrice confusion: {}".format(cm), file=f)
the matrix look like this :
Model: Model_SVC
Accuracy: 0.5692307692307692
matrice confusion: [[ 34 4 46]
[ 10 2 33]
[ 16 3 112]]
Model: Model_G_NB
Accuracy: 0.43846153846153846
matrice confusion: [[31 22 31]
[10 13 22]
[27 34 70]]
Model: Model_LR
Accuracy: 0.5461538461538461
matrice confusion: [[ 30 4 50]
[ 11 0 34]
[ 16 3 112]]
Model: Model_RF
Accuracy: 0.5846153846153846
matrice confusion: [[ 40 5 39]
[ 17 1 27]
[ 20 0 111]]
Model: Model_KN
Accuracy: 0.4846153846153846
matrice confusion: [[33 10 41]
[14 12 19]
[41 9 81]]
Model: Model_MLP
Accuracy: 0.5153846153846153
matrice confusion: [[ 17 0 67]
[ 12 0 33]
[ 13 1 117]]
I want Something like this :
F C M
0 34 4 46
1 10 2 33
2 16 3 112
3 31 22 31 => second cm
4 10 13 22
5 27 34 70
6 30 4 50 => third cm
7 11 0 34
8 16 3 112
...
Since I am using a "for ", I would like the cm to follw each other so that at the end I will be able to export the data in one excel or csv file. A data frame which can combined all the cm printing one after another.