Time series forecasting with LightGBM
Project description
LazyProphet
LazyProphet is a time series forecasting model built for LightGBM forecasting of single time series.
Many nice-ities have been added such as recursive forecasting when using lagged target variable such as the last 4 values to predict the 5th.
Additionally, fourier basis functions and penalized weighted piecewise linear basis functions are options as well!
Don't ever use in-sample fit for these types of models as they fit the data quite snuggly.
Quickstart
pip install LazyProphet
Simple example from Sklearn, just give it the hyperparameters and an array:
from LazyProphet import LazyProphet as lp
from sklearn.datasets import fetch_openml
import matplotlib.pyplot as plt
bike_sharing = fetch_openml("Bike_Sharing_Demand", version=2, as_frame=True)
y = bike_sharing.frame['count']
y = y[-400:].values
lp_model = lp.LazyProphet(seasonal_period=[24, 168], #list means we use both seasonal periods
n_basis=4, #weighted piecewise basis functions
fourier_order=10,
ar=list(range(1,25)),
decay=.99 #the 'penalized' in penalized weighted piecewise linear basis functions
)
fitted = lp_model.fit(y)
predicted = lp_model.predict(100)
plt.plot(y)
plt.plot(np.append(fitted, predicted))
plt.axvline(400)
plt.show()
If you are working with less data or then you will probably want to pass custom LightGBM params via boosting_params when creating the LazyProphet obj.
The default params are:
boosting_params = {
"objective": "regression",
"metric": "rmse",
"verbosity": -1,
"boosting_type": "gbdt",
"seed": 42,
'linear_tree': False,
'learning_rate': .15,
'min_child_samples': 5,
'num_leaves': 31,
'num_iterations': 50
}
WARNING Passing linear_tree=True can be extremely unstable, especially with ar and n_basis arguments. We do tests for linearity and will de-trend if necessary. **
Most importantly for controlling the complexity by using num_leaves/learning_rate for complexity with less data.
Alternatively, you could try out the method:
tree_optimize(y, exogenous=None, cv_splits=3, test_size=None)
In-place of the fit method. This will do 'cv_splits' number of Time-Series Cross-Validation steps to optimize the tree using Optuna. This method has some degraded performance in testing but may be better for autoforecasting various types of data sizes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for LazyProphet-0.3.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5290727add1215daf14d6a4ad659db5248d33576cd7280fdbfe7260abab21e4 |
|
MD5 | e920dfc86d1e665dae75731bc04326dd |
|
BLAKE2b-256 | 85b5e728f2e1c42d8c2afac669cf56f96d32f8feda346416c4f2b53c923bb2c7 |