Home » Machine Learning/Artificial Intelligence

Root-Mean-Square Error (RMSE) | Machine Learning

Root-Mean-Square Error (RMSE): In this article, we are going to learn one of the methods to determine the accuracy of our model in predicting the target values.
Submitted by Raunak Goswami, on August 16, 2018

Hello learners, welcome to yet another article on machine learning. Today we would be looking at one of the methods to determine the accuracy of our model in predicting the target values. All of you reading this article must have heard about the term RMS i.e. Root Mean Square and you might have also used RMS values in statistics as well. In machine Learning when we want to look at the accuracy of our model we take the root mean square of the error that has occurred between the test values and the predicted values mathematically:

For a single value:

    Let a= (predicted value- actual value) ^2
    Let b= mean of a = a (for single value)
    Then RMSE= square root of b 

For a wide set of values RMSE is defined as follows:

rmse in ML/AI



rmse in ML/AI image 2

As you can see in this scattered graph the red dots are the actual values and the blue line is the set of predicted values drawn by our model. Here X represents the distance between the actual value and the predicted line this line represents the error, similarly, we can draw straight lines from each red dot to the blue line. Taking mean of all those distances and squaring them and finally taking the root will give us RMSE of our model.

Let us write a python code to find out RMSE values of our model. We would be predicting the brain weight of the users. We would be using linear regression to train our model, the data set used in my code can be downloaded from here: headbrain6

Python code:

# -*- coding: utf-8 -*-
Created on Sun Jul 29 22:21:12 2018

@author: Raunak Goswami
import time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#reading the data
here the directory of my code and the headbrain6.csv file 
is same make sure both the files are stored in same folder or directory

#splitting the data into training and test
from sklearn.cross_validation import train_test_split

#fitting simple linear regression to the training set
from sklearn.linear_model import LinearRegression

#predict the test result

#to see the relationship between the training data values

#to see the relationship between the predicted 
#brain weight values using scattered graph
plt.ylabel('brain weight')

#errorin each value
for i in range(0,60):
print("Error in value number",i,(y_test[i]-y_pred[i]))

#combined rmse value
print("Final rmse value is =",np.sqrt(np.mean((y_test-y_pred)**2)))


rmse in ML/AI - output

rmse in ML/AI - output

rmse in ML/AI - output

The RMSE value of our is coming out to be approximately 73 which is not bad. A good model should have an RMSE value less than 180. In case you have a higher RMSE value, this would mean that you probably need to change your feature or probably you need to tweak your hyperparameters. In case you want to know how did the model predicted the values, just have a look at my previous article on linear regression.


Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.