pycaret.classification.optimize_threshold#

pycaret.classification.optimize_threshold(estimator, optimize: str = 'Accuracy', return_data: bool = False, plot_kwargs: dict | None = None, verbose: bool = True, **shgo_kwargs)[source]#

This function optimizes probability threshold for a trained classifier. It uses the SHGO optimizer from scipy to optimize for the given metric. This function will display a plot of the performance metrics at each probability threshold checked by the optimizer and returns the best model based on the metric defined under optimize parameter.

Example

>>> from pycaret.datasets import get_data
>>> juice = get_data('juice')
>>> experiment_name = setup(data = juice,  target = 'Purchase')
>>> lr = create_model('lr')
>>> best_lr_threshold = optimize_threshold(lr)
Parameters:

estimator (object) – A trained model object should be passed as an estimator.

optimizestr, default = ‘Accuracy’

Metric to be used for selecting best model.

return_databool, default = False

When set to True, data used for visualization is also returned.

plot_kwargsdict, default = {} (empty dict)

Dictionary of arguments passed to the visualizer class.

verbose: bool, default = True

Whether to print out messages at end of every iteration or not.

**shgo_kwargs:

Kwargs to pass to scipy.optimize.shgo.

Return type:

Trained Model

Warning

  • This function does not support multiclass classification problems.