.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mlearning/clustering_model/plot_clustering_api.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_mlearning_clustering_model_plot_clustering_api.py: API === Here are some examples of the machine learning API applied to clustering models. .. GENERATED FROM PYTHON SOURCE LINES 30-32 Import ------ .. GENERATED FROM PYTHON SOURCE LINES 32-43 .. code-block:: default 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() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-46 Get available clustering models ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: default print(get_clustering_models()) .. rst-class:: sphx-glr-script-out .. code-block:: none ['GaussianMixture', 'KMeans'] .. GENERATED FROM PYTHON SOURCE LINES 49-51 Get clustering model options ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: default print(get_clustering_options("GaussianMixture")) .. rst-class:: sphx-glr-script-out .. code-block:: none +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ | Name | Description | Type | +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ | n_components | The number of components of the gaussian mixture. | integer | | transformer | The strategies to transform the variables. the values are instances of | object | | | :class:`.transformer` 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:`.transformer` 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 - 16:28:12: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ INFO - 16:28:12: | Name | Description | Type | INFO - 16:28:12: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ INFO - 16:28:12: | n_components | The number of components of the gaussian mixture. | integer | INFO - 16:28:12: | transformer | The strategies to transform the variables. the values are instances of | object | INFO - 16:28:12: | | :class:`.transformer` while the keys are the names of either the variables or the groups | | INFO - 16:28:12: | | of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression algorithms. | | INFO - 16:28:12: | | if a group is specified, the :class:`.transformer` will be applied to all the variables of | | INFO - 16:28:12: | | this group. if :attr:`.identity`, do not transform the variables. | | INFO - 16:28:12: | var_names | The names of the variables. if ``none``, consider all variables mentioned in the learning | null | INFO - 16:28:12: | | dataset. | | INFO - 16:28:12: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ {'$schema': 'http://json-schema.org/schema#', 'type': 'object', 'properties': {'transformer': {'description': 'The strategies to transform the variables. The values are instances of :class:`.Transformer` 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:`.Transformer` 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'}}, 'required': ['n_components', 'transformer']} .. GENERATED FROM PYTHON SOURCE LINES 54-56 Create clustering model ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 56-62 .. code-block:: default iris = create_benchmark_dataset("IrisDataset") model = create_clustering_model("KMeans", data=iris, n_clusters=3) model.learn() print(model) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.0.0/lib/python3.9/site-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning warnings.warn( KMeans(n_clusters=3, random_state=0, var_names=None) based on the scikit-learn library built from 150 learning samples .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.125 seconds) .. _sphx_glr_download_examples_mlearning_clustering_model_plot_clustering_api.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_clustering_api.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_clustering_api.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_