Git Product home page Git Product logo

confusion_matrix's Introduction

cf_matrix.py

This file contains a function called make_confusion_matrix which can be used to create a useful visualzation of a Confusion Matrix passed in as a two dimensional numpy array.

Docstring

This function will make a pretty plot of an sklearn Confusion Matrix cm using a Seaborn heatmap visualization.

Arguments
---------
cf:            confusion matrix to be passed in

group_names:   List of strings that represent the labels row by row to be shown in each square.

categories:    List of strings containing the categories to be displayed on the x,y axis. Default is 'auto'

count:         If True, show the raw number in the confusion matrix. Default is True.

normalize:     If True, show the proportions for each category. Default is True.

cbar:          If True, show the color bar. The cbar values are based off the values in the confusion matrix.
               Default is True.

xyticks:       If True, show x and y ticks. Default is True.

xyplotlabels:  If True, show 'True Label' and 'Predicted Label' on the figure. Default is True.

sum_stats:     If True, display summary statistics below the figure. Default is True.

figsize:       Tuple representing the figure size. Default will be the matplotlib rcParams value.

cmap:          Colormap of the values displayed from matplotlib.pyplot.cm. Default is 'Blues'
               See http://matplotlib.org/examples/color/colormaps_reference.html

confusion_matrix

confusion_matrix's People

Contributors

dtrimarchi10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

confusion_matrix's Issues

Incorrect docstring

Hi,

The docstring contains a variable normalize.
However, this is not a legal parameter to pass to the function make_confusion_matrix().
Thank you for openly publishing this function :)

y-tick mark in the wrong location

This code works great but the y-tick marks and annotations are misaligned rather than centered. I have changed my version of matplotlib as it seemed to be a known version issue and even used the "plt.yticks([0.5,1.5]" trick but still the labels are not centered.
image
Snippet of Code:
# MAKE THE HEATMAP VISUALIZATION
plt.figure(figsize=figsize)
sns.heatmap(cf,annot=box_labels,fmt="",cmap=cmap,cbar=cbar,xticklabels=categories,yticklabels=categories)
if xyplotlabels:
plt.ylabel('True', fontsize=16)
plt.xlabel('Predicted' + stats_text, fontsize=16)
plt.xticks([0.5,1.5], fontsize=16)
plt.yticks([0.5,1.5], fontsize=16, ha="center", va="bottom")
else:
plt.xlabel(stats_text)

if title:
    plt.title(title)

make_confusion_matrix(cm_rf)

save the confusion matrix as png

Hello,

Thank you for the function. I ran into 1 issue while saving the chart into png. The error was "'NoneType' object has no attribute 'savefig'". Do you know what would have cause the object to be classify as NoneType?

Percentage value calculation

The percentage calculation was incorrect (python 3).
The percentage was based on the total sum of cf, but should be based on the column sums.
I am using the following hack but I am sure the code can be more elegant.

if percent:
    tmp = cf/np.sum(cf,axis=1).reshape(-1,1)
    group_percentages = ["{0:.1%}".format(value) for value in tmp.flatten()]

Question

Hello what a good graph

I have a question, what is the difference between Accurancy and precision

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.