How to calculate mean squared error in Python

Mean squared error or MSE, measures the average squared distance between two sets of values. A large MSE indicates data points being widely spread, while a small MSE indicates the opposite.

Solution for How to calculate mean squared error in Python : You can use numpy.subtract(), numpy.square(), and numpy.ndarray.mean() to calculate mean squared error Call numpy.subtract(x1,x2) to return the difference of arrays x1 and x2 as an array. Call numpy.square(x) with x as the previous result to square every difference. Use numpy.ndarray.mean() with ndarray as the previous result to return the mean of all squared differences. This approach also works for multi-dimensional arrays.


how-to-calculate-mean-squared-error-in-python