API

Here are some examples of the machine learning API applied to clustering models.

Import

from __future__ import annotations

from gemseo import configure_logger
from gemseo import create_benchmark_dataset
from gemseo.mlearning import create_clustering_model
from gemseo.mlearning import get_clustering_models
from gemseo.mlearning import get_clustering_options

configure_logger()
<RootLogger root (INFO)>

Get available clustering models

get_clustering_models()
['GaussianMixture', 'KMeans']

Get clustering model options

get_clustering_options("GaussianMixture")
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|            Name           |                                        Description                                         |            Type           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|        n_components       |                     The number of components of the gaussian mixture.                      |          integer          |
|        random_state       |  The random state passed to the random number generator. use an integer for reproducible   |          integer          |
|                           |                                          results.                                          |                           |
|        transformer        |           The strategies to transform the variables. the values are instances of           |           object          |
|                           |   :class:`.basetransformer` while the keys are the names of either the variables or the    |                           |
|                           |   groups of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression    |                           |
|                           | algorithms. if a group is specified, the :class:`.basetransformer` will be applied to all  |                           |
|                           |     the variables of this group. if :attr:`.identity`, do not transform the variables.     |                           |
|         var_names         | The names of the variables. if ``none``, consider all variables mentioned in the learning  |            null           |
|                           |                                          dataset.                                          |                           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 01:03:38: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 01:03:38: |            Name           |                                        Description                                         |            Type           |
    INFO - 01:03:38: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 01:03:38: |        n_components       |                     The number of components of the gaussian mixture.                      |          integer          |
    INFO - 01:03:38: |        random_state       |  The random state passed to the random number generator. use an integer for reproducible   |          integer          |
    INFO - 01:03:38: |                           |                                          results.                                          |                           |
    INFO - 01:03:38: |        transformer        |           The strategies to transform the variables. the values are instances of           |           object          |
    INFO - 01:03:38: |                           |   :class:`.basetransformer` while the keys are the names of either the variables or the    |                           |
    INFO - 01:03:38: |                           |   groups of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression    |                           |
    INFO - 01:03:38: |                           | algorithms. if a group is specified, the :class:`.basetransformer` will be applied to all  |                           |
    INFO - 01:03:38: |                           |     the variables of this group. if :attr:`.identity`, do not transform the variables.     |                           |
    INFO - 01:03:38: |         var_names         | The names of the variables. if ``none``, consider all variables mentioned in the learning  |            null           |
    INFO - 01:03:38: |                           |                                          dataset.                                          |                           |
    INFO - 01:03:38: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+

{'$schema': 'http://json-schema.org/schema#', 'type': 'object', 'properties': {'transformer': {'description': 'The strategies to transform the variables. The values are instances of :class:`.BaseTransformer` while the keys are the names of either the variables or the groups of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression algorithms. If a group is specified, the :class:`.BaseTransformer` will be applied to all the variables of this group. If :attr:`.IDENTITY`, do not transform the variables.', 'type': 'object'}, 'var_names': {'description': 'The names of the variables. If ``None``, consider all variables mentioned in the learning dataset.', 'type': 'null'}, 'n_components': {'description': 'The number of components of the Gaussian mixture.', 'type': 'integer'}, 'random_state': {'description': 'The random state passed to the random number generator. Use an integer for reproducible results.', 'type': 'integer'}}}

Create clustering model

iris = create_benchmark_dataset("IrisDataset")

model = create_clustering_model("KMeans", data=iris, n_clusters=3)
model.learn()
model
KMeans(n_clusters=3, random_state=0, var_names=None)
  • based on the scikit-learn library
  • built from 150 learning samples


Total running time of the script: (0 minutes 0.124 seconds)

Gallery generated by Sphinx-Gallery