pycaret.time_series.compare_models#

pycaret.time_series.compare_models(include: List[str | Any] | None = None, exclude: List[str] | None = None, fold: int | Any | None = None, round: int = 4, cross_validation: bool = True, sort: str = 'MASE', n_select: int = 1, budget_time: float | None = None, turbo: bool = True, errors: str = 'ignore', fit_kwargs: dict | None = None, engine: Dict[str, str] | None = None, verbose: bool = True, parallel: ParallelBackend | None = None)[source]#

This function trains and evaluates performance of all estimators available in the model library using cross validation. The output of this function is a score grid with average cross validated scores. Metrics evaluated during CV can be accessed using the get_metrics function. Custom metrics can be added or removed using add_metric and remove_metric function.

Example

>>> from pycaret.datasets import get_data
>>> airline = get_data('airline')
>>> from pycaret.time_series import *
>>> exp_name = setup(data = airline,  fh = 12)
>>> best_model = compare_models()
include: list of str or sktime compatible object, default = None

To train and evaluate select models, list containing model ID or scikit-learn compatible object can be passed in include param. To see a list of all models available in the model library use the models function.

exclude: list of str, default = None

To omit certain models from training and evaluation, pass a list containing model id in the exclude parameter. To see a list of all models available in the model library use the models function.

fold: int or scikit-learn compatible CV generator, default = None

Controls cross-validation. If None, the CV generator in the fold_strategy parameter of the setup function is used. When an integer is passed, it is interpreted as the ‘n_splits’ parameter of the CV generator in the setup function.

round: int, default = 4

Number of decimal places the metrics in the score grid will be rounded to.

cross_validation: bool, default = True

When set to False, metrics are evaluated on holdout set. fold param is ignored when cross_validation is set to False.

sort: str, default = ‘MASE’

The sort order of the score grid. It also accepts custom metrics that are added through the add_metric function.

n_select: int, default = 1

Number of top_n models to return. For example, to select top 3 models use n_select = 3.

budget_time: int or float, default = None

If not None, will terminate execution of the function after budget_time minutes have passed and return results up to that point.

turbo: bool, default = True

When set to True, it excludes estimators with longer training times. To see which algorithms are excluded use the models function.

errors: str, default = ‘ignore’

When set to ‘ignore’, will skip the model with exceptions and continue. If ‘raise’, will break the function when exceptions are raised.

fit_kwargs: dict, default = {} (empty dict)

Dictionary of arguments passed to the fit method of the model.

engine: Optional[Dict[str, str]] = None

The engine to use for the models, e.g. for auto_arima, users can switch between “pmdarima” and “statsforecast” by specifying engine={“auto_arima”: “statsforecast”}

verbose: bool, default = True

Score grid is not printed when verbose is set to False.

parallel: pycaret.internal.parallel.parallel_backend.ParallelBackend, default = None

A ParallelBackend instance. For example if you have a SparkSession session, you can use FugueBackend(session) to make this function running using Spark. For more details, see FugueBackend

Returns:

Trained model or list of trained models, depending on the n_select param.

Warning

  • Changing turbo parameter to False may result in very high training times.

  • No models are logged in MLflow when cross_validation parameter is False.