feat: Add max_length parameter to improve inference times #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a
max_lengthparameter to improve inference times by using only the last N values of each time series for training and forecasting. This feature can significantly speed up inference for long time series while maintaining forecast accuracy.Changes Made
Core Implementation
max_lengthparameter to baseForecasterclass constructor_maybe_truncate_series()method that efficiently truncates each time series to the last N observationsforecast()andcross_validation()methods to apply truncation before model trainingmax_lengthparameterModel Support
max_length:ADIDA,AutoARIMA,SeasonalNaive,TimesFMNonefor unlimited length)API Integration
max_lengthparameter toTimeCopilotagent classforecast()method to accept per-callmax_lengthoverride--max_lengthparameterTesting & Documentation
Usage Examples
Python API:
CLI:
# Use last 100 observations for faster inference timecopilot forecast data.csv --max_length 100Performance Benefits
Testing shows significant performance improvements:
max_length=30: 60% reduction in data processingmax_length=10: 86% reduction in data processingThe feature maintains forecast accuracy by preserving the most recent data points, which are typically most relevant for forecasting.
Data Integrity
The implementation ensures:
Fixes #106.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.