pycaret.time_series.tune_model#
- pycaret.time_series.tune_model(estimator, fold: int | Any | None = None, round: int = 4, n_iter: int = 10, custom_grid: Dict[str, list] | Any | None = None, optimize: str = 'MASE', custom_scorer=None, search_algorithm: str | None = None, choose_better: bool = True, fit_kwargs: dict | None = None, return_tuner: bool = False, verbose: bool = True, tuner_verbose: int | bool = True, **kwargs)[source]#
This function tunes the hyperparameters of a given estimator. The output of this function is a score grid with CV scores by fold of the best selected model based on
optimizeparameter. Metrics evaluated during CV can be accessed using theget_metricsfunction. Custom metrics can be added or removed usingadd_metricandremove_metricfunction.Example
>>> from pycaret.datasets import get_data >>> airline = get_data('airline') >>> from pycaret.time_series import * >>> exp_name = setup(data = airline, fh = 12) >>> dt = create_model('dt_cds_dt') >>> tuned_dt = tune_model(dt)
- estimator: sktime compatible object
Trained model object
- fold: int or scikit-learn compatible CV generator, default = None
Controls cross-validation. If None, the CV generator in the
fold_strategyparameter of thesetupfunction is used. When an integer is passed, it is interpreted as the ‘n_splits’ parameter of the CV generator in thesetupfunction.- round: int, default = 4
Number of decimal places the metrics in the score grid will be rounded to.
- n_iter: int, default = 10
Number of iterations in the grid search. Increasing ‘n_iter’ may improve model performance but also increases the training time.
- custom_grid: dictionary, default = None
To define custom search space for hyperparameters, pass a dictionary with parameter name and values to be iterated. Custom grids must be in a format supported by the defined
search_library.- optimize: str, default = ‘MASE’
Metric name to be evaluated for hyperparameter tuning. It also accepts custom metrics that are added through the
add_metricfunction.- custom_scorer: object, default = None
custom scoring strategy can be passed to tune hyperparameters of the model. It must be created using
sklearn.make_scorer. It is equivalent of adding custom metric using theadd_metricfunction and passing the name of the custom metric in theoptimizeparameter. Will be deprecated in future.- search_algorithm: str, default = ‘random’
use ‘random’ for random grid search and ‘grid’ for complete grid search.
- choose_better: bool, default = True
When set to True, the returned object is always better performing. The metric used for comparison is defined by the
optimizeparameter.- fit_kwargs: dict, default = {} (empty dict)
Dictionary of arguments passed to the fit method of the tuner.
- return_tuner: bool, default = False
When set to True, will return a tuple of (model, tuner_object).
- verbose: bool, default = True
Score grid is not printed when verbose is set to False.
- tuner_verbose: bool or in, default = True
If True or above 0, will print messages from the tuner. Higher values print more messages. Ignored when
verboseparam is False.- **kwargs:
Additional keyword arguments to pass to the optimizer.
- Returns:
Trained Model and Optional Tuner Object when
return_tuneris True.