#!/usr/bin/env python # coding: utf-8 #

Please cite us if you use the software

# # Example-7 (How to plot via seaborn+pandas) # ⚠️ This example is deprecated. You can use `plot` method from `version 3.0` # ## Environment check # Checking that the notebook is running on Google Colab or not. # In[1]: import sys try: import google.colab get_ipython().system('{sys.executable} -m pip -q -q install pycm') except: pass # ## Install seaborn,pandas # In[2]: get_ipython().system('{sys.executable} -m pip -q -q install seaborn;') get_ipython().system('{sys.executable} -m pip -q -q install pandas;') # ## Plotting # In[3]: from pandas import * import seaborn as sns from pycm import * import numpy as np # In[4]: def plot_confusion_matrix(cm,normalize=False, title='Confusion matrix', annot=False, cmap="YlGnBu"): if normalize == True: df = DataFrame(cm.normalized_matrix).T.fillna(0) else: df = DataFrame(cm.matrix).T.fillna(0) ax = sns.heatmap(df, annot=annot, cmap=cmap) ax.set_title(title) ax.set(xlabel='Predict', ylabel='Actual') # In[5]: np.random.seed(100) x1 = np.random.randint(low=0, high=3, size=20000) x2 = np.random.randint(low=0, high=3, size=20000) cm1 = ConfusionMatrix(x1, x2) plot_confusion_matrix(cm1, title="cm1", annot=True) # In[6]: plot_confusion_matrix(cm1,normalize=True, title="cm1(Normalized)", annot=True) # In[7]: x1 = np.random.randint(low=0, high=50, size=2000000) x2 = np.random.randint(low=0, high=50, size=2000000) cm2 = ConfusionMatrix(x1, x2) plot_confusion_matrix(cm2, title="cm2", cmap="Dark2") # In[8]: plot_confusion_matrix(cm2, normalize=True, title="cm2(Normalized)") # # #