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

Add Cyclic Boosting Machines (CBM) integration #128

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- window-ops
- xgboost
- pip:
- cyclicbm
- datasetsforecast
- fugue[ray]
- lightgbm_ray
Expand Down
5 changes: 3 additions & 2 deletions mlforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,11 @@ def fit_transform(
def _update_y(self, new: np.ndarray) -> None:
"""Appends the elements of `new` to every time serie.

These values are used to update the transformations and are stored as predictions.
"""
These values are used to update the transformations and are stored as predictions."""
if not hasattr(self, "y_pred"):
self.y_pred = []
if new.ndim > 1:
new = new.flatten()
self.y_pred.append(new)
new_arr = np.asarray(new)
self.ga = self.ga.append(new_arr)
Expand Down
2 changes: 2 additions & 0 deletions nbs/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@
" These values are used to update the transformations and are stored as predictions.\"\"\"\n",
" if not hasattr(self, 'y_pred'):\n",
" self.y_pred = []\n",
" if new.ndim > 1:\n",
" new = new.flatten()\n",
" self.y_pred.append(new)\n",
" new_arr = np.asarray(new)\n",
" self.ga = self.ga.append(new_arr) \n",
Expand Down
49 changes: 49 additions & 0 deletions nbs/forecast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,55 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07a06d35-77c4-417f-83fa-7057167a5f71",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"import cbm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c2d0009-1a41-4dc3-868f-3cdab0265ef9",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# cyclic boosting machine integration\n",
"fcst_test = MLForecast(\n",
" models=cbm.CBM(),\n",
" lags=[1],\n",
" num_threads=1,\n",
" freq='D'\n",
")\n",
"df_test = generate_daily_series(1, n_static_features=2, static_as_categorical=True)\n",
"fcst_test.fit(\n",
" df_test,\n",
" static_features=['static_0', 'static_1'],\n",
" prediction_intervals=PredictionIntervals(),\n",
")\n",
"pred_test = fcst_test.predict(12)\n",
"pred_int_test = fcst_test.predict(12, level=[80, 90])\n",
"# test same structure\n",
"test_eq(\n",
" pred_test,\n",
" pred_int_test[pred_test.columns]\n",
")\n",
"# test monotonicity of intervals\n",
"test_eq(\n",
" pred_int_test.filter(regex='lo|hi').apply(\n",
" lambda x: x.is_monotonic_increasing,\n",
" axis=1\n",
" ).sum(),\n",
" len(pred_int_test)\n",
")"
]
},
{
"cell_type": "markdown",
"id": "505aadfd-076d-42e6-8103-aeef4eef61b7",
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = apache2
status = 3
requirements = numba pandas scikit-learn window-ops
distributed_requirements = dask[complete] fugue[ray] pyspark lightgbm_ray xgboost_ray
dev_requirements = black datasetsforecast flake8 lightgbm matplotlib mypy nbdev pylint statsforecast xgboost
dev_requirements = black cyclicbm datasetsforecast flake8 lightgbm matplotlib mypy nbdev pylint statsforecast xgboost
nbs_path = nbs
doc_path = _docs
recursive = True
Expand Down