# Calculating the Root Mean Squared Error

## Prerequisites

### Calculating the 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 = [-42, 22, 32, 12]
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 formula:rmse = \sqrt{(\frac{1}{n})\sum_{i=1}^{n}(y_{i} - x_{i})^{2}}

#### code (Python)

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)