# Here’s how to calculate the root mean square error.

Assume you have one set of numbers that represent the Actual values you want to predict.

`Actual = [1 2 3 4];`

Then assume you have another set of numbers that Predicted the actual values.

`Predicted = [1 3 1 4];`

How do you evaluate how close Predicted values are to the Actual values?

Well you could use the root mean square error (RMSE) to give a sense of the Predicted values error.

Here’s some MATLAB code that does exactly that.

```% rmse tutorial.   % The actual values that we want to predict. Actual = [1 2 3 4];   % The values we actually predicted. Predicted = [1 3 1 4];   % One way is to use the Root Mean Square function and pass in the "error" part. rmse = rms(Predicted-Actual)   % That's it! You're done. % But for those of you who are the curious type, % here's how to calculate the root-mean-square-error by hand.   % First calculate the "error". err = Actual - Predicted;   % Then "square" the "error". squareError = err.^2;   % Then take the "mean" of the "square-error". meanSquareError = mean(squareError);   % Then take the "root" of the "mean-square-error" to get % the root-mean-square-error!   rootMeanSquareError = sqrt(meanSquareError)   % That's it! You have calculated the RMSE by hand.   % So, this is true. rootMeanSquareError == rmse```
Posted on Categories MATLAB

## 8 thoughts on “Root Mean Square Error tutorial – MATLAB”

1. Ros says:

How can I compute the “relative” rmse? Thanks in advance

2. maecy says:

How can i get a predicted values? Im doing GM(1,1) and dont know how to get a predicted data/value

1. Jeremy says:

What’s GM(1,1)? The predicted values would come from some model you have. I just made them up for this example.

3. Ângelo Paulino says:

I actually figured out that i was doing it wrong… -.-”
Thanks anyway!

1. Jeremy says:

Glad you figured it out Ângelo!

4. Ângelo Paulino says:

Using MATLAB’s rms() gives me a diferent result from your calculation. Any idea why?

Thanks!

5. Roman says:

Thanks!