Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Multi-Output Forecasting | Multi-Step Forecasting Strategies
Quizzes & Challenges
Quizzes
Challenges
/
Machine Learning for Time Series Forecasting

bookMulti-Output Forecasting

Multi-output regression is a powerful approach in time series forecasting that enables you to predict several future time points simultaneously, rather than just the next step. Instead of training a separate model for each forecast horizon or chaining predictions recursively, you train a single model that outputs a vector of future values in one shot. This method can be especially useful when you want to generate forecasts for multiple time steps ahead and capture dependencies between those future values.

123456789101112131415161718192021222324252627282930313233
import numpy as np from sklearn.ensemble import RandomForestRegressor from sklearn.multioutput import MultiOutputRegressor from sklearn.model_selection import train_test_split # Generate dummy time series data np.random.seed(42) n_samples = 300 window_size = 10 n_outputs = 3 # predict next 3 time steps # Create input windows and corresponding targets X = [] y = [] series = np.cumsum(np.random.randn(n_samples + window_size + n_outputs)) for i in range(n_samples): X.append(series[i:i+window_size]) y.append(series[i+window_size:i+window_size+n_outputs]) X = np.array(X) y = np.array(y) # Split data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False) # Build and train multi-output regressor base_regressor = RandomForestRegressor(n_estimators=100, random_state=42) multi_output_model = MultiOutputRegressor(base_regressor) multi_output_model.fit(X_train, y_train) # Predict next 3 steps for the test set y_pred = multi_output_model.predict(X_test) print("Predicted shape:", y_pred.shape) # Should be (n_test_samples, 3) print("First prediction:", y_pred[0])
copy

Multi-output forecasting offers clear benefits in certain scenarios. By predicting several future steps at once, you reduce error propagation that can occur in recursive strategies, where each prediction depends on the previous one. This approach can also capture the joint structure and dependencies among future values, which is often missed when using separate direct models for each horizon. However, multi-output models come with some limitations. They typically require more data to train effectively, since the model must learn to predict a higher-dimensional output. The model complexity also increases, making it more prone to overfitting if not managed carefully. Additionally, as the number of forecast steps grows, it becomes increasingly challenging for a single model to accurately capture all future dependencies, especially in highly volatile or non-stationary series.

1. What is a benefit of multi-output forecasting compared to recursive and direct strategies?

2. What challenge arises when using multi-output models for long forecast horizons?

question mark

What is a benefit of multi-output forecasting compared to recursive and direct strategies?

Select the correct answer

question mark

What challenge arises when using multi-output models for long forecast horizons?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain how to choose the right number of output steps for multi-output regression?

What are some strategies to prevent overfitting in multi-output time series models?

Are there specific scenarios where multi-output forecasting is not recommended?

bookMulti-Output Forecasting

Swipe to show menu

Multi-output regression is a powerful approach in time series forecasting that enables you to predict several future time points simultaneously, rather than just the next step. Instead of training a separate model for each forecast horizon or chaining predictions recursively, you train a single model that outputs a vector of future values in one shot. This method can be especially useful when you want to generate forecasts for multiple time steps ahead and capture dependencies between those future values.

123456789101112131415161718192021222324252627282930313233
import numpy as np from sklearn.ensemble import RandomForestRegressor from sklearn.multioutput import MultiOutputRegressor from sklearn.model_selection import train_test_split # Generate dummy time series data np.random.seed(42) n_samples = 300 window_size = 10 n_outputs = 3 # predict next 3 time steps # Create input windows and corresponding targets X = [] y = [] series = np.cumsum(np.random.randn(n_samples + window_size + n_outputs)) for i in range(n_samples): X.append(series[i:i+window_size]) y.append(series[i+window_size:i+window_size+n_outputs]) X = np.array(X) y = np.array(y) # Split data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False) # Build and train multi-output regressor base_regressor = RandomForestRegressor(n_estimators=100, random_state=42) multi_output_model = MultiOutputRegressor(base_regressor) multi_output_model.fit(X_train, y_train) # Predict next 3 steps for the test set y_pred = multi_output_model.predict(X_test) print("Predicted shape:", y_pred.shape) # Should be (n_test_samples, 3) print("First prediction:", y_pred[0])
copy

Multi-output forecasting offers clear benefits in certain scenarios. By predicting several future steps at once, you reduce error propagation that can occur in recursive strategies, where each prediction depends on the previous one. This approach can also capture the joint structure and dependencies among future values, which is often missed when using separate direct models for each horizon. However, multi-output models come with some limitations. They typically require more data to train effectively, since the model must learn to predict a higher-dimensional output. The model complexity also increases, making it more prone to overfitting if not managed carefully. Additionally, as the number of forecast steps grows, it becomes increasingly challenging for a single model to accurately capture all future dependencies, especially in highly volatile or non-stationary series.

1. What is a benefit of multi-output forecasting compared to recursive and direct strategies?

2. What challenge arises when using multi-output models for long forecast horizons?

question mark

What is a benefit of multi-output forecasting compared to recursive and direct strategies?

Select the correct answer

question mark

What challenge arises when using multi-output models for long forecast horizons?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3
some-alt