I have two time series (forecast and realization) and both start as of 2003 until today. I need to calculate the RMSE for each month and for each year. Could you please help me with the code. I used np.sqrt(metrics.mean_squared_error(actual, forecast))
but it gives RMSE for the whole set.
Many thanks!
Asked
Active
Viewed 896 times
-1

Tochiza
- 9
- 1
- 1
-
I think you need to look into slicing – Shan S Jul 01 '20 at 17:01
1 Answers
0
I assume your data is a pandas
dataframe. If so, you want to group by months and then aggregate by rmse
:
from sklearn.metrics import mean_squared_error
df["differ"] = df["Forecast"] - df["Actual"]
rmseser = df.groupby(['Year', 'Month']).differ.agg(lambda x: sqrt(np.sum(x * x))

Igor Rivin
- 4,632
- 2
- 23
- 35
-
it seems that it's not working at my end - I got "'DataFrameGroupBy' object has no attribute 'differ'" – Tochiza Jul 01 '20 at 19:59