feat: add support for more neural models#338
Conversation
There was a problem hiding this comment.
Pull request overview
This PR expands timecopilot.models by adding additional auto-tuned NeuralForecast and MLForecast model wrappers, and by standardizing/supporting quantiles-based probabilistic outputs (while explicitly rejecting level) for these “Auto*” model families.
Changes:
- Added new NeuralForecast auto model wrappers:
AutoNBEATS,AutoDeepAR,AutoPatchTST, and enabledquantilessupport for the existing auto neural models viaMQLoss+QuantileConverter. - Added multiple new MLForecast auto model wrappers (e.g.,
AutoXGBoost,AutoCatboost, linear models, forests) and addedcatboost/xgboostas core dependencies. - Updated exports (
timecopilot.models.__init__) and test coverage for the expanded model set; added/updated changelog entries.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
timecopilot/models/neural.py |
Adds new auto neural wrappers and routes probabilistic output through QuantileConverter + MQLoss. |
timecopilot/models/ml.py |
Adds new AutoMLForecast-based wrappers and a shared run_automlforecast_model helper for quantile outputs. |
timecopilot/models/__init__.py |
Re-exports new ML and neural models in the public package surface. |
tests/models/conftest.py |
Registers the new models in the test matrix with minimal configs for speed. |
tests/models/test_models.py |
Updates tests to reflect quantile support and the expanded auto-model set. |
pyproject.toml |
Adds catboost and xgboost to runtime dependencies. |
uv.lock |
Locks new dependencies (notably catboost, xgboost, graphviz updates). |
docs/changelogs/v0.0.25.md |
Adds new feature notes (but modifies an existing release file). |
docs/changelogs/v0.0.26.md |
Introduces a new changelog entry for quantile support improvements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from mlforecast.auto import ( | ||
| AutoCatboost as _AutoCatboost, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoElasticNet as _AutoElasticNet, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoLasso as _AutoLasso, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoLightGBM as _AutoLightGBM, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoLinearRegression as _AutoLinearRegression, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoMLForecast, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoRandomForest as _AutoRandomForest, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoRidge as _AutoRidge, | ||
| ) | ||
| from mlforecast.auto import ( | ||
| AutoXGBoost as _AutoXGBoost, | ||
| ) | ||
| from mlforecast.utils import PredictionIntervals | ||
|
|
||
| from .utils.forecaster import Forecaster, get_seasonality | ||
| from .utils.forecaster import Forecaster, QuantileConverter, get_seasonality |
| ### Features | ||
|
|
||
| * **New neural models**: Added 3 new auto neural models powered by `neuralforecast`: `AutoNBEATS`, `AutoDeepAR`, and `AutoPatchTST`. All support `quantiles` for probabilistic forecasts trained with `MQLoss` and follow the same interface as the existing `AutoNHITS` and `AutoTFT`. | ||
|
|
||
| ```python | ||
| import pandas as pd | ||
| from timecopilot.models.neural import AutoDeepAR, AutoNBEATS, AutoPatchTST | ||
|
|
||
| df = pd.read_csv( | ||
| "https://timecopilot.s3.amazonaws.com/public/data/air_passengers.csv", | ||
| parse_dates=["ds"], | ||
| ) | ||
|
|
||
| model = AutoNBEATS() | ||
| fcst_df = model.forecast(df, h=12, quantiles=[0.1, 0.5, 0.9]) | ||
| ``` | ||
|
|
||
| * **New ML models**: Added 7 new auto ML models powered by `mlforecast`'s hyperparameter optimization: `AutoLinearRegression`, `AutoXGBoost`, `AutoRidge`, `AutoLasso`, `AutoElasticNet`, `AutoRandomForest`, and `AutoCatboost`. All models support `quantiles` for probabilistic forecasts via conformal prediction and follow the same interface as the existing `AutoLGBM`. | ||
|
|
| if level is not None and quantiles is not None: | ||
| raise ValueError( | ||
| "You must not provide both `level` and `quantiles` simultaneously." | ||
| ) | ||
| if level is not None: | ||
| raise ValueError( | ||
| "Level is not supported for AutoNBEATS. " | ||
| "Please use `quantiles` instead." | ||
| ) | ||
|
|
||
| inferred_freq = self._maybe_infer_freq(df, freq) | ||
| qc = QuantileConverter(level=None, quantiles=quantiles) | ||
| loss = MQLoss(level=qc.level) if qc.level is not None else MAE() | ||
| if self.config is None: | ||
| config = _AutoNBEATS.get_default_config(h=h, backend="ray") | ||
| config["scaler_type"] = tune.choice(["robust"]) | ||
| else: | ||
| config = self.config | ||
| if self.backend == "optuna": |
| def test_using_level(model): | ||
| level = [0, 20, 40, 60, 80] # corresponds to qs [0.1, 0.2, ..., 0.9] | ||
| df = generate_series(n_series=2, freq="D") | ||
| if model.alias in [ | ||
| _level_unsupported = { | ||
| "AutoLGBM", | ||
| "AutoLinearRegression", | ||
| "AutoXGBoost", | ||
| "AutoRidge", | ||
| "AutoLasso", | ||
| "AutoElasticNet", | ||
| "AutoRandomForest", | ||
| "AutoCatboost", | ||
| "AutoNHITS", | ||
| "AutoTFT", | ||
| "PatchTST-FM", | ||
| ]: | ||
| # These models do not support levels yet | ||
| "AutoNBEATS", | ||
| "AutoDeepAR", | ||
| "AutoPatchTST", | ||
| } | ||
| if model.alias in _level_unsupported: | ||
| # these models only support quantiles, not level | ||
| with pytest.raises(ValueError) as excinfo: | ||
| model.forecast( | ||
| df=df, | ||
| h=2, | ||
| freq="D", | ||
| level=level, | ||
| ) | ||
| assert "not supported" in str(excinfo.value) | ||
| assert "quantiles" in str(excinfo.value) | ||
| return |
Co-authored-by: AzulGarza <10517170+AzulGarza@users.noreply.github.com>
|
|
Resolved the merge conflicts in a7fa6ba. The merge brings in origin/main (commits bebe988 and 63059d9) while keeping all changes from the current PR. Conflict resolutions:
|
There was a problem hiding this comment.
Pull request overview
Adds additional NeuralForecast “auto” neural forecasters to the timecopilot.models surface area, along with tests and changelog updates.
Changes:
- Added new neural model wrappers:
AutoNBEATS,AutoDeepAR,AutoPatchTST. - Exported new models from
timecopilot.modelsand included them in the test matrix/fixtures. - Updated changelogs to document the new neural models.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
timecopilot/models/neural.py |
Adds NeuralForecast auto-model wrappers for NBEATS, DeepAR, PatchTST using the existing wrapper pattern. |
timecopilot/models/__init__.py |
Exposes the new neural models at the package level via imports and __all__. |
tests/models/test_models.py |
Updates tests to account for new neural auto aliases (min-length handling, quantile monotonicity exceptions, level unsupported list). |
tests/models/conftest.py |
Adds the new models to the parametrized test model fixture with lightweight configs. |
docs/changelogs/v0.0.26.md |
Documents the new neural models and provides a usage example. |
docs/changelogs/v0.0.25.md |
Removes an extra blank line in the features section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) | ||
| from neuralforecast.auto import ( | ||
| AutoNBEATS as _AutoNBEATS, | ||
| ) | ||
| from neuralforecast.auto import ( | ||
| AutoNHITS as _AutoNHITS, | ||
| ) | ||
| from neuralforecast.auto import ( | ||
| AutoPatchTST as _AutoPatchTST, | ||
| ) | ||
| from neuralforecast.auto import ( |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
this pr adds support for more neural models