0

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



enter image description here

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

EMMAKENJI
  • 359
  • 2
  • 5
  • 14
  • 2
    It's a [known issue](https://github.com/mwaskom/seaborn/issues/1773) in matplotlib `3.1.1` - you can try downgrading to `3.0.3` – Chris Adams Dec 17 '19 at 08:46
  • 1
    thank you I will follow your link – EMMAKENJI Dec 17 '19 at 09:29
  • 1
    @ChrisA I used version 3.1.0 and it workend , but I have a proble for the last case : the number 112 appears like 1.1e+02M , I do not know why since When i print the confusion matrix on the terminal the numbers apeears correctly – EMMAKENJI Dec 17 '19 at 11:15
  • try using arguments `annot=True, fmt='0'` in `heatmap` method ..? – Chris Adams Dec 17 '19 at 11:17

0 Answers0