pycaret.clustering.create_model#
- pycaret.clustering.create_model(model: str | Any, num_clusters: int = 4, ground_truth: str | None = None, round: int = 4, fit_kwargs: dict | None = None, verbose: bool = True, experiment_custom_tags: Dict[str, Any] | None = None, engine: str | None = None, **kwargs)[source]#
This function trains and evaluates the performance of a given model. Metrics evaluated can be accessed using the
get_metricsfunction. Custom metrics can be added or removed using theadd_metricandremove_metricfunction. All the available models can be accessed using themodelsfunction.Example
>>> from pycaret.datasets import get_data >>> jewellery = get_data('jewellery') >>> from pycaret.clustering import * >>> exp_name = setup(data = jewellery) >>> kmeans = create_model('kmeans')
- model: str or scikit-learn compatible object
ID of an model available in the model library or pass an untrained model object consistent with scikit-learn API. Models available in the model library (ID - Name):
‘kmeans’ - K-Means Clustering
‘ap’ - Affinity Propagation
‘meanshift’ - Mean shift Clustering
‘sc’ - Spectral Clustering
‘hclust’ - Agglomerative Clustering
‘dbscan’ - Density-Based Spatial Clustering
‘optics’ - OPTICS Clustering
‘birch’ - Birch Clustering
‘kmodes’ - K-Modes Clustering
- num_clusters: int, default = 4
The number of clusters to form.
- ground_truth: str, default = None
ground_truth to be provided to evaluate metrics that require true labels. When None, such metrics are returned as 0.0. All metrics evaluated can be accessed using
get_metricsfunction.- round: int, default = 4
Number of decimal places the metrics in the score grid will be rounded to.
- fit_kwargs: dict, default = {} (empty dict)
Dictionary of arguments passed to the fit method of the model.
- verbose: bool, default = True
Status update is not printed when verbose is set to False.
- 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 K-Means Clustering (“kmeans”), users can switch between “sklearn” and “sklearnex” by specifying engine=”sklearnex”.
- **kwargs:
Additional keyword arguments to pass to the estimator.
- Returns:
Trained Model
Warning
num_clustersparam not required for Affinity Propagation (‘ap’), Mean shift (‘meanshift’), Density-Based Spatial Clustering (‘dbscan’) and OPTICS Clustering (‘optics’).When fit doesn’t converge in Affinity Propagation (‘ap’) model, all datapoints are labelled as -1.
Noisy samples are given the label -1, when using Density-Based Spatial (‘dbscan’) or OPTICS Clustering (‘optics’).
OPTICS (‘optics’) clustering may take longer training times on large datasets.