How to find the RMSE.. !
조회 수: 29 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Jaynik
2024년 7월 16일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!