• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 06, 2022 |980 Views
Python program to calculate mean squared error
  Share   Like
Description
Discussion

In this video, we will write a python program to calculate mean squared error. 

We have covered two approaches in this video: 
1. Using scikit-learn module 
2. Using NumPy module 

Approach 1: Using scikit-learn module: 
We define two Python lists, representing true values and predicted values. We import the mean_squared_error function from sklearn.metrics module. We pass the true values list and predicted values list in mean_squared_error function, this function returns a float type value. This value is our required MSE value. 

Approach 2: Using NumPy module: In this approach we define 2 lists representing true values and predicted values. We create a numpy array of the difference between each item of two lists using numpy.subtract() method. We square each item in the result array using numpy.square() function. Finally, we calculate the mean of the array using .mean() function of NumPy Array. The result is our required MSE value. 

Python | Mean Squared Error: https://www.geeksforgeeks.org/python-mean-squared-error/

Read More