Evaluating the model
Evaluating the model’s performance is essential to understanding how well it forecasts future values. For time series models, you can use metrics for regression tasks. Two common metrics are mean squared error (MSE) and mean absolute error (MAE). Other metrics are covered in Chapter 5. Additionally, you can visualize the actual versus predicted values to see how well the model captures the time series’ patterns. Let’s try it:
- Begin by importing the metrics from scikit-learn for
mean_squared_error
andmean_absolute_error
. Prepare for plotting the data by importingmatplotlib.pyplot
. - Next, use the scikit-learn metrics,
mean_squared_error
andmean_absolute_error
, to compare the predicted values,y_pred
, to the ground truth values in the test dataset,y_test
:mse = mean_squared_error(y_test, y_pred) mae = mean_absolute_error(y_test, y_pred) print(f'Mean Squared Error: {mse}') print(f'Mean Absolute Error: {mae}')
We...