How to find the RMSE.. !
55 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Jaynik
el 16 de Jul. de 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 comentarios
Ver también
Categorías
Más información sobre Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!