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_clusters        |                      The number of clusters of the k-means algorithm.                      |          integer          |
|        random_state       | The random state passed to the method generating the initial centroids. use an integer for |          integer          |
|                           |                                   reproducible 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  |           array           |
|                           |                                          dataset.                                          |                           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 10:42:06: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 10:42:06: |            Name           |                                        Description                                         |            Type           |
    INFO - 10:42:06: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 10:42:06: |         n_clusters        |                      The number of clusters of the k-means algorithm.                      |          integer          |
    INFO - 10:42:06: |        random_state       | The random state passed to the method generating the initial centroids. use an integer for |          integer          |
    INFO - 10:42:06: |                           |                                   reproducible results.                                    |                           |
    INFO - 10:42:06: |        transformer        |           The strategies to transform the variables. the values are instances of           |           object          |
    INFO - 10:42:06: |                           |   :class:`.basetransformer` while the keys are the names of either the variables or the    |                           |
    INFO - 10:42:06: |                           |   groups of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression    |                           |
    INFO - 10:42:06: |                           | algorithms. if a group is specified, the :class:`.basetransformer` will be applied to all  |                           |
    INFO - 10:42:06: |                           |     the variables of this group. if :attr:`.identity`, do not transform the variables.     |                           |
    INFO - 10:42:06: |         var_names         | The names of the variables. if ``none``, consider all variables mentioned in the learning  |           array           |
    INFO - 10:42:06: |                           |                                          dataset.                                          |                           |
    INFO - 10:42:06: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+

{'$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': 'array'}, 'n_clusters': {'description': 'The number of clusters of the K-means algorithm.', 'type': 'integer'}, 'random_state': {'description': 'The random state passed to the method generating the initial centroids. 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=())
  • based on the scikit-learn library
  • built from 150 learning samples


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

Gallery generated by Sphinx-Gallery