ChronosForecaster
ChronosForecaster
- class ChronosForecaster(model_path: str, config: dict = None, seed: int | None = None, use_source_package: bool = False, ignore_deps: bool = False)[source]
Interface to the Chronos and Chronos-Bolt Zero-Shot Forecaster by Amazon Research.
Chronos and Chronos-Bolt are pretrained time-series foundation models developed by Amazon for time-series forecasting. This method has been proposed in [2] and official code is given at [1].
Note: vanilla Chronos is not exogenous capable despite being so advertised in [2]. The “exogenous capable” version is actually a composite forecaster rather than an exogenous capable foundation model.
To obtain this “exogenous capable” version of Chronos as advertised in [2], combine
ChronosForecasterwith an exogenous capable forecaster viaResidualBoostingForecaster. The original reference uses tabularized linear regression, i.e.,YtoX(LinearRegression()), withYtoXfromsktimeandLinearRegressionfromsklearn.- Parameters:
- model_pathstr
Path to the Chronos huggingface model.
- configdict, optional, default={}
A dictionary specifying the configuration settings for the model. The available configuration options include hyperparameters that control the prediction behavior, sampling, and hardware preferences. In case of the
Chronosmodel, the dictionary can include the following keys:- “num_samples”int, optional
The number of samples to generate during prediction. Median of these samples is taken to get prediction for each timestamp.
- “temperature”float, optional
Sampling temperature for prediction. A higher value increases the randomness of predictions, while a lower value makes them more deterministic.
- “top_k”int, optional
Limits the sampling pool to the top k predictions during sampling.
- “top_p”float, optional
Cumulative probability threshold for nucleus sampling. Controls the diversity of the predictions.
The below configuration options are available in both model options: - “limit_prediction_length” : bool, default=False
If True, limits the length of the predictions to the model’s context length.
- “torch_dtype”torch.dtype, default=torch.bfloat16
Data type to use for model weights and operations (e.g., torch.float32, torch.float16, or torch.bfloat16).
- “device_map”str, default=”cpu”
Specifies the device on which to run the model, e.g., “cpu” for CPU inference, “cuda” for GPU, or “mps” for Apple Silicon.
If not provided, the default values from the pretrained model or system configuration are used.
- seed: int, optional, default=None
Random seed for transformers.
- use_source_package: bool, optional, default=False
If True, the model will be loaded directly from the source package
chronos. This is useful if you want to bypass the local version of the package or when working in an environment where the latest updates from the source package are needed. If False, the model will be loaded from the local version of package maintained in sktime. To install the source package, follow the instructions here [1].- ignore_deps: bool, optional, default=False
If True, dependency checks will be ignored, and the user is expected to handle the installation of required packages manually. If False, the class will enforce the default dependencies required for Chronos.
- Attributes:
- model_pipeline: ChronosPipeline or ChronosBoltPipeline
The underlying model pipeline user for forecasting
- is_bolt: bool
Indicates whether the model is a Chronos-Bolt model, to ensure effective differentiation purely from model-path.
References
Chronos: Learning the Language of Time Series
Examples
>>> # Example using 'amazon/chronos-t5-tiny' model >>> from sktime.datasets import load_airline >>> from sktime.forecasting.chronos import ChronosForecaster >>> from sktime.split import temporal_train_test_split >>> from sktime.forecasting.base import ForecastingHorizon >>> y = load_airline() >>> y_train, y_test = temporal_train_test_split(y) >>> fh = ForecastingHorizon(y_test.index, is_relative=False) >>> forecaster = ChronosForecaster("amazon/chronos-t5-tiny") >>> forecaster.fit(y_train) >>> y_pred = forecaster.predict(fh)
>>> # Example using 'amazon/chronos-bolt-tiny' model >>> from sktime.datasets import load_airline >>> from sktime.forecasting.chronos import ChronosForecaster >>> from sktime.split import temporal_train_test_split >>> from sktime.forecasting.base import ForecastingHorizon >>> y = load_airline() >>> y_train, y_test = temporal_train_test_split(y) >>> fh = ForecastingHorizon(y_test.index, is_relative=False) >>> forecaster = ChronosForecaster("amazon/chronos-bolt-tiny") >>> forecaster.fit(y_train) >>> y_pred = forecaster.predict(fh)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(y[, X, fh])Fit forecaster to training data.
fit_predict(y[, X, fh, X_pred])Fit and forecast time series at future horizon.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_pretrained_params([deep])Get pretrained parameters of this estimator.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the estimator.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
predict([fh, X, y])Forecast time series at future horizon.
predict_interval([fh, X, coverage])Compute/return prediction interval forecasts.
predict_proba([fh, X, marginal])Compute/return fully probabilistic forecasts.
predict_quantiles([fh, X, alpha])Compute/return quantile forecasts.
predict_residuals([y, X])Return residuals of time series forecasts.
predict_var([fh, X, cov])Compute/return variance forecasts.
pretrain(y[, X, fh])Pre-train forecaster on panel (global) data.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
score(y[, X, fh])Scores forecast against ground truth, using MAPE (non-symmetric).
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
update(y[, X, update_params])Update cutoff value and, optionally, fitted parameters.
update_predict(y[, cv, X, update_params, ...])Make predictions and update model iteratively over the test set.
update_predict_single([y, fh, X, update_params])Update model with new data and make forecasts.

