Resolving issue #260 ( added exogenous variables to Chronos-2 )#264
Resolving issue #260 ( added exogenous variables to Chronos-2 )#264Kushagra7777 wants to merge 8 commits intoTimeCopilot:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds exogenous variable support to Chronos-2 models by introducing a new _forecast_chronos2_df method and improving cross-validation error handling.
- Adds exogenous variable handling to Chronos-2 models via the new
_forecast_chronos2_dfmethod - Updates cross-validation to check model support for exogenous variables before raising errors
- Sets
supports_exogenousflag based on model type detection
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| timecopilot/models/foundation/chronos.py | Implements Chronos-2 specific forecasting with exogenous variables and sets the supports_exogenous flag |
| timecopilot/models/utils/forecaster.py | Improves cross-validation exogenous variable handling with model-specific error messages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
|
|
||
| required = {id_col, ts_col, target_col} | ||
| if not required.issubset(df.columns): | ||
| raise ValueError("missing required columns") |
There was a problem hiding this comment.
The error message should specify which columns are missing for better debugging. Consider: raise ValueError(f'Missing required columns: {required - set(df.columns)}')
| raise ValueError("missing required columns") | |
| missing = required - set(df.columns) | |
| raise ValueError(f"Missing required columns: {missing}") |
| pred_df = pred_df.rename(columns={id_col: "unique_id", ts_col: "ds"}) | ||
|
|
||
| if "predictions" not in pred_df.columns: | ||
| raise ValueError("predictions column missing") |
There was a problem hiding this comment.
The error message should mention the source and available columns for debugging. Consider: raise ValueError(f'predictions column missing from model output. Available columns: {list(pred_df.columns)}')
| raise ValueError("predictions column missing") | |
| raise ValueError(f"predictions column missing from model output. Available columns: {list(pred_df.columns)}") |
| exog_cols = [] | ||
| for col in df.columns: | ||
| if col not in base_cols: | ||
| exog_cols.append(col) |
There was a problem hiding this comment.
[nitpick] This loop can be simplified using a list comprehension: exog_cols = [col for col in df.columns if col not in base_cols]
| exog_cols = [] | |
| for col in df.columns: | |
| if col not in base_cols: | |
| exog_cols.append(col) | |
| exog_cols = [col for col in df.columns if col not in base_cols] |
| supports_exogenous = getattr(self, "supports_exogenous", False) | ||
| for _, (cutoffs, train, valid) in tqdm(enumerate(splits)): | ||
| if len(valid.columns) > 3: | ||
|
|
There was a problem hiding this comment.
Trailing whitespace on line 256. Remove the spaces to follow PEP 8 style guidelines.
make sense. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
saving carbon Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
saving carbon 2 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
merging from main
This PR adds exogenous-feature handling to the Chronos-2 forecast.
The function
_forecast_chronos2_dfnow identifies non target columns as exogenous inputs, prepares them consistently with the existing codebase, and passes them through predict_df.Quantile outputs follow the same pattern as other model types.