Name | TimeMurmur JSON |
Version |
0.1.3
JSON |
| download |
home_page | |
Summary | Time series forecasting at scale with LightGBM |
upload_time | 2023-12-04 15:52:59 |
maintainer | |
docs_url | None |
author | Tyler Blume |
requires_python | |
license | |
keywords |
forecasting
time series
lightgbm
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# TimeMurmur
Requires the forecast period is the same for all time series.
## Quickstart
```
pip install TimeMurmur
```
Get example dataset and ensure the date column is Datetime:
```
from TimeMurmur.utils.utility_functions import get_data
train_df = get_data()
train_df['Datetime'] = pd.to_datetime(train_df['Datetime'])
```
This dataset is a subset of the weekly data from M4, it includes the required ID, Datetime, and History columns.
The most basic model you can fit is:
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W')
predicted = murmur.predict(20)
```
These parameters are required, the freq is 'W' for Weekly following standard frequency nomenclature.
You can take a look with the helper function:
```
for i in range(3):
murmur.plot(fitted, predicted=predicted, murmur_id=i)
```
## Adding AR Lags
In order to do recursive forecasting utilizing past values, just pass a list of lags you want to the ar parameter:
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W',
n_basis=[10],
ar=[1,2,3,4])
predicted = murmur.predict(20)
```
Here we use a linear basis function with 4 ar lags passed as a list.
## Adding Seasonality
Seasonality works similar to the ar lags. We can pass multiple seasonal periods in a list if we have multiple seasonalities to account for.
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W',
n_basis=[10],
ar=[1,2,3,4],
seasonal_period=[4,52])
predicted = murmur.predict(20)
```
## LightGBM Parameters
You can pass a few of the most influential LightGBM parameters to fit such as `num_iterations` and `num_leaves`:
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W',
n_basis=[10],
ar=[1,2,3,4],
seasonal_period=[4,52],
num_iterations=100,
learning_rate=.1,
num_leaves=31)
predicted = murmur.predict(20)
```
## Fitting with category exogenous.
This is a 'ID' axis variable since it never changes across time only across IDs. Since it is a string we pass it to 'categorical_columns' as well.
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W',
n_basis=[10],
ar=[1,2,3,4],
seasonal_period=[4,52],
num_iterations=100,
learning_rate=.1,
num_leaves=31,
categorical_columns=['category'],
id_feature_columns=['category'])
predicted = murmur.predict(20)
```
## Fitting Quantiles
To fit quantiles pass `quantile` for `objective` and the desired quantile percentage to `alpha`.
```
murmur = Murmur(floor=0)
fitted = murmur.fit(train_df,
target_column='History',
id_column='ID',
date_column='Datetime',
freq='W',
n_basis=[10],
ar=[1,2,3,4],
seasonal_period=[4,52],
num_iterations=100,
learning_rate=.1,
num_leaves=31,
objective='quantile',
alpha=.9)
predicted = murmur.predict(20)
```
## Explanations with Shapley
```
#get shapley values of predictions
predicted_shap_vals = murmur.explain_predictions(predicted)
fitted_shap_vals = murmur.explain_fitted(fitted)
#plot using shapley values
murmur.plot_explanations(fitted_shap_vals=fitted_shap_vals,
predicted_shap_vals=predicted_shap_vals,
murmur_id=0)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "TimeMurmur",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "forecasting,time series,lightgbm",
"author": "Tyler Blume",
"author_email": "tblume@mail.USF.edu",
"download_url": "",
"platform": null,
"description": "# TimeMurmur\nRequires the forecast period is the same for all time series.\n## Quickstart\n```\npip install TimeMurmur\n```\nGet example dataset and ensure the date column is Datetime:\n```\nfrom TimeMurmur.utils.utility_functions import get_data\ntrain_df = get_data()\ntrain_df['Datetime'] = pd.to_datetime(train_df['Datetime'])\n```\nThis dataset is a subset of the weekly data from M4, it includes the required ID, Datetime, and History columns.\n\nThe most basic model you can fit is:\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W')\npredicted = murmur.predict(20)\n```\nThese parameters are required, the freq is 'W' for Weekly following standard frequency nomenclature.\nYou can take a look with the helper function:\n```\nfor i in range(3):\n murmur.plot(fitted, predicted=predicted, murmur_id=i)\n```\n## Adding AR Lags\nIn order to do recursive forecasting utilizing past values, just pass a list of lags you want to the ar parameter:\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W',\n n_basis=[10],\n ar=[1,2,3,4])\npredicted = murmur.predict(20)\n```\nHere we use a linear basis function with 4 ar lags passed as a list.\n## Adding Seasonality\nSeasonality works similar to the ar lags. We can pass multiple seasonal periods in a list if we have multiple seasonalities to account for.\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W',\n n_basis=[10],\n ar=[1,2,3,4],\n seasonal_period=[4,52])\npredicted = murmur.predict(20)\n```\n## LightGBM Parameters\nYou can pass a few of the most influential LightGBM parameters to fit such as `num_iterations` and `num_leaves`:\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W',\n n_basis=[10],\n ar=[1,2,3,4],\n seasonal_period=[4,52],\n num_iterations=100,\n learning_rate=.1,\n num_leaves=31)\npredicted = murmur.predict(20)\n```\n## Fitting with category exogenous.\nThis is a 'ID' axis variable since it never changes across time only across IDs. Since it is a string we pass it to 'categorical_columns' as well.\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W',\n n_basis=[10],\n ar=[1,2,3,4],\n seasonal_period=[4,52],\n num_iterations=100,\n learning_rate=.1,\n num_leaves=31,\n categorical_columns=['category'],\n id_feature_columns=['category'])\npredicted = murmur.predict(20)\n```\n## Fitting Quantiles\nTo fit quantiles pass `quantile` for `objective` and the desired quantile percentage to `alpha`.\n```\nmurmur = Murmur(floor=0)\nfitted = murmur.fit(train_df,\n target_column='History',\n id_column='ID',\n date_column='Datetime',\n freq='W',\n n_basis=[10],\n ar=[1,2,3,4],\n seasonal_period=[4,52],\n num_iterations=100,\n learning_rate=.1,\n num_leaves=31,\n objective='quantile',\n alpha=.9)\npredicted = murmur.predict(20)\n```\n\n## Explanations with Shapley\n\n```\n#get shapley values of predictions\npredicted_shap_vals = murmur.explain_predictions(predicted)\nfitted_shap_vals = murmur.explain_fitted(fitted)\n#plot using shapley values\nmurmur.plot_explanations(fitted_shap_vals=fitted_shap_vals,\n predicted_shap_vals=predicted_shap_vals,\n murmur_id=0)\n```\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Time series forecasting at scale with LightGBM",
"version": "0.1.3",
"project_urls": null,
"split_keywords": [
"forecasting",
"time series",
"lightgbm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "585e19d32e5b2a777660e01b4228915e2b0abb79b733cde9d413f6b2846c931a",
"md5": "fd2e130fc0e255a8b718c4ab9a266cfc",
"sha256": "6b4ab4872f2c06469d27acd9b58248e341da4caad04ccd25a2594f0e909773eb"
},
"downloads": -1,
"filename": "TimeMurmur-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fd2e130fc0e255a8b718c4ab9a266cfc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 27628,
"upload_time": "2023-12-04T15:52:59",
"upload_time_iso_8601": "2023-12-04T15:52:59.270763Z",
"url": "https://files.pythonhosted.org/packages/58/5e/19d32e5b2a777660e01b4228915e2b0abb79b733cde9d413f6b2846c931a/TimeMurmur-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-04 15:52:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "timemurmur"
}