Skip to main content

Evaluation Metrics for Machine Learning Model


Evaluation metrics play an important role in achieving the optimal model during model training. It is a way to quantify the performance of the Machine learning Model.
For simplicity, I'll be focusing on binary classification. But all the below metrics can be extended for multi-class classification. Let us first understand the basic building block of metrics used to evaluate a classification model. Suppose we have trained a binary image classifier model that predicts whether there is a cat or not in the image.
Positive Class: Cat is a Positive class.
Negative Class: No Cat is the Negative class, It can be anything(dog, horse, background, etc.) except cat in the image.


Fig. 1

Fig. 2
  • True Positive (TP): It is an outcome when the model correctly predicts the positive class. i.e the actual image is "Cat" and the model also predicts "Cat".
  • False Positive (FP):  It is an outcome when the model incorrectly predicts the positive class. i.e the actual image is "Cat" but the model predicts it a "Not Cat".
  • True Negative (TN): It is an outcome when the model correctly predicts the negative class. i.e the actual image is a "Not Cat" and the model also predicts it a "Cat".
  • False Negative (FN): It is an outcome when the model incorrectly predicts the negative class. i.e the actual image is a "Cat" but the model predicts it as a "Not Cat".

Classification Accuracy 

It is the ratio of correct prediction to the total number of samples.



Example: If we have 150 testing samples, and our classifier predicts 120 samples correctly. Then accuracy is 120/150 i.e 0.8 or 80%.
For a binary classification problem, accuracy can also be defined as

Recall
\[Recall=\frac{TP}{TP+FN}\]

It is the total number of TP divided by actual positives( TP + FN ).
From the above equation, we can infer the following points
  • If a model is not producing any False Negative then recall is 1.
  • If a model is not producing any True Positive then recall is 0.


Precision
\[Precision =\frac{TP}{TP+FP}\]

It is the total number of TP divide by the total number of predicted positives( TP + FP ).

From the above equation, we can infer the following points

  • If a model is not producing any False Positive then precision is 1.
  • If a model is not producing any True Positive then precision is 0.
F1 Score

\[F1=2 . \frac{Precision . Recall }{Precision + Recall }\]

It is the harmonic mean of precision and recall.

Confusion Matrix

It is also known as error Matrix, The term 'confusion' is used because it checks if the system is getting confused between classes. It gives more insight into the performance of a classification model. Fig. 2 is a matrix for multi class classification problems.

Let's again take an example of multi-class classification problem where confusion matrix helps a lot in understanding the performance and cause of error in our trained model.
If we have a trained model on CIFAR-10 data, and perform classification on test dataset. The confusion matrix is plotted in Fig.3
  • The vertical axis denotes the actual class and horizontal axis denotes the predicted class. 
  • The sum of all the numbers in any row reflects the total number of images used for testing of corresponding class. Sum of all values in any row is 1000 because we have used 1000 samples of each class for testing.
  • The sum of all the numbers in any column reflects the total number of prediction for corresponding class.
Now, look at the first row corresponding to "Cat" class. We can infer that 826 samples are predicted as "Cat",48 are predicted as "Dog", 12 are predicted as "Horse" and so on... all of which are actually "Cat". It means we have predicted 826 samples correctly.
We can also infer that Cat is getting confused mostly with "Dog".
From second row we can infer that 801 "Dog" images samples are correclty predicted, but 111 samples of "Dog" are predicted as "Cat".
From this we infer that "Cat" and "Dog" are confused with each other, and our accuracy is dropping  beacause of this isssue.
Using the above insights we can do necessary changes in our model and data.

Thanks for reading.





Comments

  1. Good Explanation ,I got to know more

    ReplyDelete
  2. Great post. keep sharing such a worthy information
    Sales Force CPQ Online Training Hyderabad
    Visit us: sales force CPQ Online Training

    ReplyDelete
  3. This is a good site and a really nice point of view.I learned lots of useful information.Social Media Training in Chennai
    Social Media Training Institute in Chennai

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Great blog.thanks for sharing such a useful information
    Java training chennai

    ReplyDelete
  6. Great blog. Thanks for sharing such a useful information. Share more.
    Jira Training Online
    Jira Course Online

    ReplyDelete
  7. This post is so interactive and informative.keep update more information...
    Web Designing Course in Tambaram
    Web Designing Course in chennai

    ReplyDelete

  8. This post is so interactive and informative.keep update more information...
    Digital Marketing Course in Tambaram
    Digital Marketing Course in Chennai


    ReplyDelete

  9. This post is so interactive and informative.keep update more information...
    DevOps course in Tambaram
    DevOps Training in Chennai

    ReplyDelete

Post a Comment

Popular Posts

Transparent Image overlay(Alpha blending) with OpenCV and Python

(a)Final Blended Image                     (b) Background Image                             (c)Foreground Image                               Alpha blending Alpha blending is the process of overlaying a foreground image with transparency over a background Image. The transparent image is generally a PNG image.It consists of four channels (RGBA).The fourth channel is the alpha channel which holds the transparency magnitude. Image (b) is a background image and image (c) is the foreground / overlay image. Image (a) is the final blended image obtained by blending  the overalay image using the alpha mask.  Below is the image(Fig d) of the alpha channel of the overlay  image. (d).Alpha Channel At every pixel of the image, we blend the background...

Fast Pixel Processing with OpenCV and Python

In this post. I will explain how fast pixel manipulation of an image can be done in Python and OpenCV. Image processing is a CPU intensive task. It involves processing on large arrays. Hence when you are implementing your Image Processing algorithm, you algorithm needs to be highly efficient. The type of operation that can be applied on an Image can be classified into three categories.