pycaret.regression.create_model#

pycaret.regression.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, experiment_custom_tags: Dict[str, Any] | None = None, engine: str | None = None, verbose: bool = True, return_train_score: bool = False, **kwargs)[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_metrics function. Custom metrics can be added or removed using add_metric and remove_metric function. All the available models can be accessed using the models function.

Example

>>> from pycaret.datasets import get_data
>>> boston = get_data('boston')
>>> from pycaret.regression import *
>>> exp_name = setup(data = boston,  target = 'medv')
>>> 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’ - Linear Regression

  • ‘lasso’ - Lasso Regression

  • ‘ridge’ - Ridge Regression

  • ‘en’ - Elastic Net

  • ‘lar’ - Least Angle Regression

  • ‘llar’ - Lasso Least Angle Regression

  • ‘omp’ - Orthogonal Matching Pursuit

  • ‘br’ - Bayesian Ridge

  • ‘ard’ - Automatic Relevance Determination

  • ‘par’ - Passive Aggressive Regressor

  • ‘ransac’ - Random Sample Consensus

  • ‘tr’ - TheilSen Regressor

  • ‘huber’ - Huber Regressor

  • ‘kr’ - Kernel Ridge

  • ‘svm’ - Support Vector Regression

  • ‘knn’ - K Neighbors Regressor

  • ‘dt’ - Decision Tree Regressor

  • ‘rf’ - Random Forest Regressor

  • ‘et’ - Extra Trees Regressor

  • ‘ada’ - AdaBoost Regressor

  • ‘gbr’ - Gradient Boosting Regressor

  • ‘mlp’ - MLP Regressor

  • ‘xgboost’ - Extreme Gradient Boosting

  • ‘lightgbm’ - Light Gradient Boosting Machine

  • ‘catboost’ - CatBoost Regressor

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.

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.

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.

engine: Optional[str] = None

The execution engine to use for the model, e.g. for Linear Regression (“lr”), users can switch between “sklearn” and “sklearnex” by specifying engine=”sklearnex”.

verbose: bool, default = True

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

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

  • Models are not logged on the MLFlow server when cross_validation param is set to False.