I tried to plot my confusion matrix but for a strange reason, It does not look quite good, Could help me figure out how can I improve it ?
below the code and display on jupyter notebook ::
import codecs
import re
import os
import sys, argparse
import csv
from itertools import islice
import pickle
from collections import defaultdict, Counter
import numpy as np
import pandas as pd
from pandas import read_excel
from pandas import read_csv
from pandas.plotting import scatter_matrix
from matplotlib import pyplot as plt
import seaborn as sns
%matplotlib inline
def classifieur(X, y):
# Building matrix
X = feature(X) #
model1 = LinearSVC()
model2 = MultinomialNB()
model3 = LogisticRegression()
models = {'model_SVC':model1 , 'model_NB': model2, 'model_LR': model3}
cv = KFold(n_splits=10, shuffle=False, random_state=None)
for model_name, model in models.items():
y_pred = cross_val_predict(model, X, y, cv=cv)
# print("Model: {}".format(model_name))
# print("Accuracy: {}".format(accuracy_score(y, y_pred)))
cm = confusion_matrix(ylabels, y_pred)
# print("matrice confusion: {}".format(cm))
# Transform to cm_df for easier plotting
cm_v = pd.DataFrame(cm,
index = ['C','F','M'],
columns = ['C','F','M'])
plt.figure(figsize=(6,4))
sns.heatmap(cm_v, annot=True)
plt.title('{}'.format(model_name))
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
classifieur(X, y)
Traceback
2019-12-17 09:33:59,895 - matplotlib.colorbar - DEBUG - locator: <matplotlib.ticker.MaxNLocator object at 0x7f8748813ad0>
2019-12-17 09:33:59,896 - matplotlib.colorbar - DEBUG - Using auto colorbar locator on colorbar
2019-12-17 09:33:59,896 - matplotlib.colorbar - DEBUG - locator: <matplotlib.ticker.MaxNLocator object at 0x7f8748813ad0>
2019-12-17 09:33:59,897 - matplotlib.colorbar - DEBUG - Setting pcolormesh
As you can see the part of it does not appeared or are masked and these lines keep appearing before the cm :
2019-12-17 09:33:59,895 - matplotlib.colorbar - DEBUG - locator: 2019-12-17 09:33:59,896 - matplotlib.colorbar - DEBUG - Using auto colorbar locator on colorbar 2019-12-17 09:33:59,896 - matplotlib.colorbar - DEBUG - locator: 2019-12-17 09:33:59,897 - matplotlib.colorbar - DEBUG - Setting pcolormesh