How to find the RMSE.. !
15 views (last 30 days)
Show older comments
I am learning to calculate the RMSE, so i just created the simplest data that i could think of-
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
i have used the basic fitting tools to plot the linear trend-
For RMSE, i need the actual data values and estimated data values, how to find the estimated data values or is there a way to just calculate the RMSE?
0 Comments
Answers (1)
Jaynik
on 16 Jul 2024
Hi Sophia,
The Root Mean Square Error (RMSE) is a measure of how well your model's predictions match the actual data. It is calculated as the square root of the average of the squared differences between the predicted and actual values.
In your case, you have the actual data values in your array a. The estimated data values would be the values predicted by your linear trend model. Here is a sample code to find rmse:
% Your actual data
a = [2 3 4 5 1 6 3 6 7 8];
years = 1979:1988;
% Fit a linear model to your data using polyfit or any other function
p = polyfit(years, a, 1);
% Use the model to estimate values
estimated = polyval(p, years);
% Calculate the differences between actual and estimated values
differences = a - estimated;
% Square the differences
squaredDifferences = differences .^ 2;
% Calculate the mean of the squared differences
meanSquaredDifference = mean(squaredDifferences);
% Take the square root to get the RMSE
rmse = sqrt(meanSquaredDifference);
This script first fits a linear model to your data using the polyfit function. It then uses this model to estimate values for each year using the polyval function. The differences between the actual and estimated values are calculated, squared, and then averaged. The square root of this average is your RMSE.
You can also directly use the rmse function using the actual and forecast data. You can read more about it here:
Hope this helps!
0 Comments
See Also
Categories
Find more on Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!