Untitled
unknown
plain_text
2 years ago
1.2 kB
6
Indexable
for i in range(len(data) - window_size - forecast_steps + 1): # Select the training data for this fold train_data = data.iloc[i:i + window_size] # Fit the exponential smoothing model model = ExponentialSmoothing(train_data['Value'], trend='add', seasonal='add', seasonal_periods=12) fitted_model = model.fit() # Forecast for the specified number of steps forecast = fitted_model.forecast(steps=forecast_steps) # Store the forecasted values forecasted_values.append(forecast) # Convert the list of arrays into a DataFrame forecast_df = pd.DataFrame(forecasted_values, index=data.index[window_size:window_size + len(forecasted_values)]) # Calculate mean squared error for each forecasted step mse_per_step = [] actual_values = data['Value'][window_size + forecast_steps - 1:] for step in range(forecast_steps): forecast_values = forecast_df.iloc[:, step] mse = mean_squared_error(actual_values, forecast_values) mse_per_step.append(mse) # Print the mean squared error for each forecasted step for step, mse in enumerate(mse_per_step): print(f"Step {step + 1}: Mean Squared Error = {mse:.2f}")
Editor is loading...