Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/output chunk length regression model #761

Merged
merged 30 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5c492c1
fix multicollinearity in regression ensemble model tests causing expl…
brunnedu Jan 14, 2022
40f7a80
reset seed to intial value
brunnedu Jan 14, 2022
bc3be03
add output_chunk_length parameter to regression model
brunnedu Jan 25, 2022
3637541
Merge branch 'master' of https://github.com/unit8co/darts into feat/o…
brunnedu Jan 25, 2022
1332f99
add output_chunk_length to fit method of regressionmodel
brunnedu Jan 25, 2022
b05e952
add check if model support multi output regression natively
brunnedu Jan 25, 2022
561719f
remove _shift_matrices test
brunnedu Jan 25, 2022
67874cf
update the LightGBMModel
brunnedu Jan 26, 2022
78532c6
update linear regression model
brunnedu Jan 26, 2022
0209f38
update random forest regression model
brunnedu Jan 26, 2022
0d40e06
update LightGBMModel docstring
brunnedu Jan 26, 2022
0ac1073
use dict for lags in regressionmodel and adjust all models and tests …
brunnedu Jan 26, 2022
e31d797
reformat regression_ensemble_model using pre-commit
brunnedu Jan 30, 2022
f12b81c
reformat test_regression_models with pre-commit
brunnedu Jan 30, 2022
22763c5
shorten comment line length
brunnedu Jan 30, 2022
a2f2d82
remove unused import to pass flake8
brunnedu Jan 31, 2022
d4107f4
reformat with black
brunnedu Jan 31, 2022
a377401
reformat with black
brunnedu Jan 31, 2022
19181d7
update docstring of _create_lagged_data
brunnedu Jan 31, 2022
684a86e
reformat using black
brunnedu Jan 31, 2022
ef83068
Merge branch 'master' into feat/output-chunk-length-regression-model
brunnedu Jan 31, 2022
4ad9d72
improve error message when unable to build any samples to fit and whe…
brunnedu Feb 1, 2022
3bf57df
Merge branch 'master' of https://github.com/unit8co/darts into feat/o…
brunnedu Feb 1, 2022
c6d3257
Merge branch 'feat/output-chunk-length-regression-model' of https://g…
brunnedu Feb 1, 2022
352e9b0
Merge branch 'master' into feat/output-chunk-length-regression-model
brunnedu Feb 1, 2022
cf5367f
Merge branch 'master' into feat/output-chunk-length-regression-model
brunnedu Feb 1, 2022
d44a188
return self at the end of fit() in regressionmodel
brunnedu Feb 1, 2022
d189844
remove numpydoc type hints and add n_jobs_multioutput_wrapper paramet…
brunnedu Feb 5, 2022
6c73682
add comments
brunnedu Feb 5, 2022
770b63a
Merge branch 'master' into feat/output-chunk-length-regression-model
brunnedu Feb 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions darts/models/forecasting/gradient_boosted_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
LightGBM Model
--------------

This is a LightGBM implementation of Gradient Boosted Trees algorightm.
This is a LightGBM implementation of Gradient Boosted Trees algorithm.

To enable LightGBM support in Darts, follow the detailed install instructions for LightGBM in the README:
https://github.com/unit8co/darts/blob/master/README.md
Expand All @@ -23,7 +23,8 @@ def __init__(
lags: Union[int, list] = None,
lags_past_covariates: Union[int, List[int]] = None,
lags_future_covariates: Union[Tuple[int, int], List[int]] = None,
**kwargs
output_chunk_length: int = 1,
**kwargs,
):
"""Light Gradient Boosted Model

Expand All @@ -41,6 +42,10 @@ def __init__(
given the last `past` lags in the past are used (inclusive, starting from lag -1) along with the first
`future` future lags (starting from 0 - the prediction time - up to `future - 1` included). Otherwise a list
of integers with lags is required.
output_chunk_length
Number of time steps predicted at once by the internal regression model. Does not have to equal the forecast
horizon `n` used in `predict()`. However, setting `output_chunk_length` equal to the forecast horizon may
be useful if the covariates don't extend far enough into the future.
**kwargs
Additional keyword arguments passed to `lightgbm.LGBRegressor`.
"""
Expand All @@ -50,13 +55,12 @@ def __init__(
lags=lags,
lags_past_covariates=lags_past_covariates,
lags_future_covariates=lags_future_covariates,
output_chunk_length=output_chunk_length,
model=lgb.LGBMRegressor(**kwargs),
)

def __str__(self):
return "LGBModel(lags={}, lags_past={}, lags_future={})".format(
self.lags, self.lags_past_covariates, self.lags_future_covariates
)
return f"LGBModel(lags={self.lags})"

def fit(
self,
Expand All @@ -67,7 +71,7 @@ def fit(
val_past_covariates: Optional[Union[TimeSeries, Sequence[TimeSeries]]] = None,
val_future_covariates: Optional[Union[TimeSeries, Sequence[TimeSeries]]] = None,
max_samples_per_ts: Optional[int] = None,
**kwargs
**kwargs,
):
"""
Fits/trains the model using the provided list of features time series and the target time series.
Expand Down Expand Up @@ -109,7 +113,7 @@ def fit(
past_covariates=past_covariates,
future_covariates=future_covariates,
max_samples_per_ts=max_samples_per_ts,
**kwargs
**kwargs,
)

return self
13 changes: 7 additions & 6 deletions darts/models/forecasting/linear_regression_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(
lags: Union[int, list] = None,
lags_past_covariates: Union[int, List[int]] = None,
lags_future_covariates: Union[Tuple[int, int], List[int]] = None,
output_chunk_length: int = 1,
**kwargs,
):
"""Linear regression model.
Expand All @@ -37,6 +38,10 @@ def __init__(
given the last `past` lags in the past are used (inclusive, starting from lag -1) along with the first
`future` future lags (starting from 0 - the prediction time - up to `future - 1` included). Otherwise a list
of integers with lags is required.
output_chunk_length
Number of time steps predicted at once by the internal regression model. Does not have to equal the forecast
horizon `n` used in `predict()`. However, setting `output_chunk_length` equal to the forecast horizon may
be useful if the covariates don't extend far enough into the future.
**kwargs
Additional keyword arguments passed to `sklearn.linear_model.LinearRegression`.
"""
Expand All @@ -45,13 +50,9 @@ def __init__(
lags=lags,
lags_past_covariates=lags_past_covariates,
lags_future_covariates=lags_future_covariates,
output_chunk_length=output_chunk_length,
model=LinearRegression(**kwargs),
)

def __str__(self):
return (
f"LinearRegression(lags={self.lags}, "
f"lags_past_covariates={self.lags_past_covariates}, "
f"lags_historical_covariates={self.lags_historical_covariates}, "
f"lags_future_covariates={self.lags_future_covariates})"
)
return f"LinearRegression(lags={self.lags})"
9 changes: 6 additions & 3 deletions darts/models/forecasting/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
lags: Union[int, list] = None,
lags_past_covariates: Union[int, List[int]] = None,
lags_future_covariates: Union[Tuple[int, int], List[int]] = None,
output_chunk_length: int = 1,
n_estimators: Optional[int] = 100,
max_depth: Optional[int] = None,
**kwargs,
Expand All @@ -48,6 +49,10 @@ def __init__(
given the last `past` lags in the past are used (inclusive, starting from lag -1) along with the first
`future` future lags (starting from 0 - the prediction time - up to `future - 1` included). Otherwise a list
of integers with lags is required.
output_chunk_length
Number of time steps predicted at once by the internal regression model. Does not have to equal the forecast
horizon `n` used in `predict()`. However, setting `output_chunk_length` equal to the forecast horizon may
be useful if the covariates don't extend far enough into the future.
n_estimators : int
The number of trees in the forest.
max_depth : int
Expand All @@ -66,14 +71,12 @@ def __init__(
lags=lags,
lags_past_covariates=lags_past_covariates,
lags_future_covariates=lags_future_covariates,
output_chunk_length=output_chunk_length,
model=RandomForestRegressor(**kwargs),
)

def __str__(self):
return (
f"RandomForest(lags={self.lags}, "
f"lags_past_covariates={self.lags_past_covariates}, "
f"lags_historical_covariates={self.lags_historical_covariates}, "
f"lags_future_covariates={self.lags_future_covariates}, "
f"n_estimators={self.n_estimators}, max_depth={self.max_depth})"
)
22 changes: 7 additions & 15 deletions darts/models/forecasting/regression_ensemble_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from typing import Optional, List, Union, Sequence, Tuple
from darts.timeseries import TimeSeries
from darts.logging import get_logger, raise_if
from darts.logging import get_logger, raise_if, raise_if_not

from darts.models.forecasting.forecasting_model import (
ForecastingModel,
Expand Down Expand Up @@ -58,20 +58,12 @@ def __init__(
lags_future_covariates=[0], model=regression_model
)

raise_if(
regression_model.lags is not None
and regression_model.lags_historical_covariates is not None
and regression_model.lags_past_covariates is not None
and regression_model.lags_future_covariates != [0],
(
f"`lags`, `lags_historical_covariates` and `lags_past_covariates` "
f"of regression model must be `None` "
f"and `lags_future_covariates` must be [0]. Given:\n"
f"`lags`: {regression_model.lags}, "
f"`lags_historical_covariates`: {regression_model.lags_historical_covariates}, "
f"`lags_past_covariates`: {regression_model.lags} and "
f"`lags_future_covariates`: {regression_model.lags_future_covariates}."
),
# check lags of the regression model
raise_if_not(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

regression_model.lags == {"future": [0]},
f"`lags` and `lags_past_covariates` of regression model must be `None`"
f"and `lags_future_covariates` must be [0]. Given:\n"
f"{regression_model.lags}",
)

self.regression_model = regression_model
Expand Down
Loading