## Root mean-squared error - L2 Loss

Root mean-squared error (RMSE) is a function for assessing Regression predictions. Sometimes called L2 Error because it takes the L2 Norm of the error vector.

### Steps

- Calculate error vector as
**labels**-**predictions** - Square the errors to make values positive.
- Take the mean of all values.
- Take the square root of the mean.

$\sqrt{\frac{1}{n} \sum\limits_{i=1}^{N} |{labels}-{predictions}|}$

An alternative to Mean Absolute Difference - L1 Loss, where the key difference is the square operation instead of the absolute value. Because the square operations penalises very wrong predictions, it is often preferred. However, some also say it can be sensitive to outliers. In my experience, it's usually worth trying both (or some combination).

Sometimes you choose not to perform the square root operation when in a loss function. In that case, the operation is called a **squared** L2 Norm and expressed $\| e\|^{2}_{2}$

In this Numpy example, the model predicted the price of 3 houses (in $) as 350k, 450k and 500k.

The houses are actually valued at 300k, 480k and 800k.

```
import numpy as np
predictions = np.array([350, 450, 500])
labels = np.array([300, 480, 800])
difference = predictions - labels
difference_squared = difference ** 2
rmse = np.sqrt(difference_squared.mean())
rmse
```

176.44640357154728