Skip to main content
Update link and code
Source Link
mloning
  • 518
  • 5
  • 13

Yes, you can use regression algorithms for forecasting. There's a good explanation of how to adapt regression algorithms to forecasting problems herehere.

As stated in the comments, you need to make sure you properly evaluate your forecasting algorithms. When you use train_test_split you random shuffle and split your data. Instead you should only use past data to fit your algorithm and then evaluate against future data.

If you're interested, we're developing a toolbox that extends scikit-learn for exactly these use cases. So with sktime, you could simply write:

import numpy as np
from sktime.datasets import load_airline
from sktime.forecasting.compose import ReducedRegressionForecastermake_reduction
from sklearn.ensemble import ExtraTreesRegressor
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.performance_metrics.forecasting import smape_lossmean_absolute_percentage_error

y = load_airline()  # load 1-dimensional time series
y_train, y_test = temporal_train_test_split(y)  
fh = np.arange(1, len(y_test) + 1)  # forecasting horizon
regressor = ExtraTreesRegressor()  
forecaster = ReducedRegressionForecastermake_reduction(regressor, window_length=10)
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
print(smape_lossmean_absolute_percentage_error(y_test, y_pred))
>>> 0.17668623103710565

Yes, you can use regression algorithms for forecasting. There's a good explanation of how to adapt regression algorithms to forecasting problems here.

As stated in the comments, you need to make sure you properly evaluate your forecasting algorithms. When you use train_test_split you random shuffle and split your data. Instead you should only use past data to fit your algorithm and then evaluate against future data.

If you're interested, we're developing a toolbox that extends scikit-learn for exactly these use cases. So with sktime, you could simply write:

import numpy as np
from sktime.datasets import load_airline
from sktime.forecasting.compose import ReducedRegressionForecaster
from sklearn.ensemble import ExtraTreesRegressor
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.performance_metrics.forecasting import smape_loss

y = load_airline()  # load 1-dimensional time series
y_train, y_test = temporal_train_test_split(y)  
fh = np.arange(1, len(y_test) + 1)  # forecasting horizon
regressor = ExtraTreesRegressor()  
forecaster = ReducedRegressionForecaster(regressor, window_length=10)
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
print(smape_loss(y_test, y_pred))
>>> 0.17668623103710565

Yes, you can use regression algorithms for forecasting. There's a good explanation of how to adapt regression algorithms to forecasting problems here.

As stated in the comments, you need to make sure you properly evaluate your forecasting algorithms. When you use train_test_split you random shuffle and split your data. Instead you should only use past data to fit your algorithm and then evaluate against future data.

If you're interested, we're developing a toolbox that extends scikit-learn for exactly these use cases. So with sktime, you could simply write:

import numpy as np
from sktime.datasets import load_airline
from sktime.forecasting.compose import make_reduction
from sklearn.ensemble import ExtraTreesRegressor
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.performance_metrics.forecasting import mean_absolute_percentage_error

y = load_airline()  # load 1-dimensional time series
y_train, y_test = temporal_train_test_split(y)  
fh = np.arange(1, len(y_test) + 1)  # forecasting horizon
regressor = ExtraTreesRegressor()  
forecaster = make_reduction(regressor, window_length=10)
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
print(mean_absolute_percentage_error(y_test, y_pred))
>>> 0.17668623103710565
Source Link
mloning
  • 518
  • 5
  • 13

Yes, you can use regression algorithms for forecasting. There's a good explanation of how to adapt regression algorithms to forecasting problems here.

As stated in the comments, you need to make sure you properly evaluate your forecasting algorithms. When you use train_test_split you random shuffle and split your data. Instead you should only use past data to fit your algorithm and then evaluate against future data.

If you're interested, we're developing a toolbox that extends scikit-learn for exactly these use cases. So with sktime, you could simply write:

import numpy as np
from sktime.datasets import load_airline
from sktime.forecasting.compose import ReducedRegressionForecaster
from sklearn.ensemble import ExtraTreesRegressor
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.performance_metrics.forecasting import smape_loss

y = load_airline()  # load 1-dimensional time series
y_train, y_test = temporal_train_test_split(y)  
fh = np.arange(1, len(y_test) + 1)  # forecasting horizon
regressor = ExtraTreesRegressor()  
forecaster = ReducedRegressionForecaster(regressor, window_length=10)
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
print(smape_loss(y_test, y_pred))
>>> 0.17668623103710565