HOME Mathematics Computer Science
Root Mean Squared Error
Prerequisites
Show All
Hide All
Mean
Show/Hide
﻿
Definition
The mean is a way of finding the average of a set of numbers. It is calculated by dividing the sum of the numbers by the count.
Example
Find the mean of the following numbers: [4, 7, 10]

sum = 4 + 7 + 10 = 21

count = 3

mean = 21 / 3 = 7

Mathematical Definition

LaTeX: \overline{x} = (\frac{1}{n})\sum_{i=1}^{n}(x_{i})
Code
import numpy

values = [4, 7, 10]

mean = numpy.average(values)
print(mean)

Notes
There are other types of mean, this one is called the 'Arithmetic Mean'. It is also called the 'Mathematical Expectation' and the 'Average'.
Mean Absolute Error
Show/Hide
﻿
Definition
The mean absolute error (mae) is a metric for determining the similarity between two sets.

The error between two numbers is simply the difference between them. The absolute error is the absolute difference. To find the mean absolute error, you must find the absolute error between corresponding values in the sets, and then find the mean of those errors.
Example
Find the mean absolute error of the following two sets of numbers:

S1 = [2, 5, 9, 2]

S2 = [6, 3, 6, 1]

1. First we calculate the differences between these numbers:

D = [2 - 6, 5 - 3, 9 - 6, 2 - 1]

D = [-4, 2, 3, 1]

2. Now we must make these numbers absolute:

D = [4, 2, 3, 1]

3. Finally, we find the mean of these numbers:

mae = (4 + 2 + 3 + 1) / 4

mae = 10 / 4

mae = 2.5

Mathematical Definition

LaTeX: mae = (\frac{1}{n})\sum_{i=1}^{n}\left | y_{i} - x_{i} \right |
Code
import sklearn.metrics

S1 = [2, 5, 9, 2]
S2 = [6, 3, 6, 1]

mae = sklearn.metrics.mean_absolute_error(S1, S2)
print(mae)


Root Mean Squared Error
﻿
Definition
The root mean squared error (rmse) is a metric for determining the similarity between two sets.

It is similar to the mean absolute error, except with a couple of extra steps:
1. Each absolute error is squared before being summed.
2. The final result (mean squared error) is square-rooted before being returned.
Example
Find the root square mean error of the following two sets of numbers:

S1 = [2, 5, 9, 2]

S2 = [6, 3, 6, 1]

1. First we calculate the differences between these numbers:

D = [2 - 6, 5 - 3, 9 - 6, 2 - 1]

D = [-4, 2, 3, 1]

2. Now we square them:

D = [-4 * -4, 2 * 2, 3 * 3, 1 * 1]

D = [16, 4, 9, 1]

3. next we find the mean of these numbers:

mean = (16 + 4 + 9 + 1) / 4

mean = 30 / 4

mean = 7.5

4. finally we square root the mean:

rmse = sqrt(mean)

rmse = 2.74 to 3 s.f.

Mathematical Definition

LaTeX: rmse = \sqrt{(\frac{1}{n})\sum_{i=1}^{n}(y_{i} - x_{i})^{2}}
Code
import sklearn.metrics
import math

S1 = [2, 5, 9, 2]
S2 = [6, 3, 6, 1]

mse = sklearn.metrics.mean_squared_error(S1, S2)
rmse = math.sqrt(mse)

print(rmse)