pycaret.classification.create_model#
- pycaret.classification.create_model(estimator: str | Any, fold: int | Any | None = None, round: int = 4, cross_validation: bool = True, fit_kwargs: dict | None = None, groups: str | Any | None = None, probability_threshold: float | None = None, experiment_custom_tags: Dict[str, Any] | None = None, engine: str | None = None, verbose: bool = True, return_train_score: bool = False, **kwargs) Any[source]#
This function trains and evaluates the performance of a given estimator using cross validation. The output of this function is a score grid with CV scores by fold. Metrics evaluated during CV can be accessed using the
get_metricsfunction. Custom metrics can be added or removed usingadd_metricandremove_metricfunction. All the available models can be accessed using themodelsfunction.Example
>>> from pycaret.datasets import get_data >>> juice = get_data('juice') >>> from pycaret.classification import * >>> exp_name = setup(data = juice, target = 'Purchase') >>> lr = create_model('lr')
- estimator: str or scikit-learn compatible object
ID of an estimator available in model library or pass an untrained model object consistent with scikit-learn API. Estimators available in the model library (ID - Name):
‘lr’ - Logistic Regression
‘knn’ - K Neighbors Classifier
‘nb’ - Naive Bayes
‘dt’ - Decision Tree Classifier
‘svm’ - SVM - Linear Kernel
‘rbfsvm’ - SVM - Radial Kernel
‘gpc’ - Gaussian Process Classifier
‘mlp’ - MLP Classifier
‘ridge’ - Ridge Classifier
‘rf’ - Random Forest Classifier
‘qda’ - Quadratic Discriminant Analysis
‘ada’ - Ada Boost Classifier
‘gbc’ - Gradient Boosting Classifier
‘lda’ - Linear Discriminant Analysis
‘et’ - Extra Trees Classifier
‘xgboost’ - Extreme Gradient Boosting
‘lightgbm’ - Light Gradient Boosting Machine
‘catboost’ - CatBoost Classifier
- 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.
- cross_validation: bool, default = True
When set to False, metrics are evaluated on holdout set.
foldparam is ignored when cross_validation is set to False.- fit_kwargs: dict, default = {} (empty dict)
Dictionary of arguments passed to the fit method of the model.
- groups: str or array-like, with shape (n_samples,), default = None
Optional group labels when GroupKFold is used for the cross validation. It takes an array with shape (n_samples, ) where n_samples is the number of rows in training dataset. When string is passed, it is interpreted as the column name in the dataset containing group labels.
- probability_threshold: float, default = None
Threshold for converting predicted probability to class label. It defaults to 0.5 for all classifiers unless explicitly defined in this parameter. Only applicable for binary classification.
- experiment_custom_tags: dict, default = None
Dictionary of tag_name: String -> value: (String, but will be string-ified if not) passed to the mlflow.set_tags to add new custom tags for the experiment.
- verbose: bool, default = True
Score grid is not printed when verbose is set to False.
- engine: Optional[str] = None
The execution engine to use for the model, e.g. for Logistic Regression (“lr”), users can switch between “sklearn” and “sklearnex” by specifying engine=”sklearnex”.
- return_train_score: bool, default = False
If False, returns the CV Validation scores only. If True, returns the CV training scores along with the CV validation scores. This is useful when the user wants to do bias-variance tradeoff. A high CV training score with a low corresponding CV validation score indicates overfitting.
- **kwargs:
Additional keyword arguments to pass to the estimator.
- Returns:
Trained Model
Warning
AUC for estimators that does not support ‘predict_proba’ is shown as 0.0000.
Models are not logged on the
MLFlowserver whencross_validationparam is set to False.