Git Product home page Git Product logo

confusion-matrix's Introduction

Confusion-Matrix

We want to predict some data using Classification in Machine Learning.

Let the classifier be SVM, Decision Tree, Random Forest, Logistic Rgression, and so on.

What are the observations? In each classifier, we get both right as well as wrong predictions.

Wrong predictions can again be categorized into:-

  • False Positive
  • False Negative

False Positive (type I error)

When we predict that something happens/occurs and it didn't happened/occured.(rejection of a true null hypothesis) Example :- We predict that an earthquake would occur which didn't happen.

False Negative (type II error)

When we predict that something won't happen/occur but it happens/occurs.(non-rejection of a false null hypothesis) Example :- We predict that there might be no earthquake but there occurs an earthquake.

Usually, type I errors are considered to be not as critical as type II errors.

But in fields like Medicine, Agriculture, both the errors might seem critical.

A 2x2 matrix denoting the right and wrong predictions might help us analyse the rate of success. This matrix is termed the Confusion Matrix.

Representation

0 1
0 TN FP
1 FN TP

The horizontal axis corresponds to the predicted values(y-predicted) and the vertical axis correspomds to the actual values(y-actual).

  • [1][1] represents the values which are predicted to be false and are actually false.
  • [1][2] represents the values which are predicted to be true, but are false.
  • [2][1] represents the values which are predicted to be false, but are true.
  • [2][2] represents the values which are predicted to be true and are actually true.

Using Confusion Matrix in code

Confusion Matrix can be used in python by importing the metrics module from sklearn.

from sklearn import metrics
cm = metrics.confusion_matrix(y_actual, y_predicted)

We can calculate the rate of success as:-

r = (TN+TP)/(FN+FP)

It can be directly interpreted by,

print("Accuracy = ",metrics.accuracy_score(y_actual, y_predicted)*100)

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.