Note
Click here to download the full example code
API¶
Here are some examples of the machine learning API applied to clustering models.
Import¶
from __future__ import division, unicode_literals
from gemseo.api import configure_logger, load_dataset
from gemseo.mlearning.api import (
create_clustering_model,
get_clustering_models,
get_clustering_options,
)
configure_logger()
Out:
<RootLogger root (INFO)>
Get available clustering models¶
print(get_clustering_models())
Out:
['GaussianMixture', 'KMeans', 'MLPredictiveClusteringAlgo']
Get clustering model options¶
print(get_clustering_options("GaussianMixture"))
Out:
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
| 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 | null |
| | :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 none, do not transform the variables. | |
| var_names | The names of the variables. if none, consider all variables mentioned in the learning | null |
| | dataset. | |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
INFO - 21:50:12: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
INFO - 21:50:12: | Name | Description | Type |
INFO - 21:50:12: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
INFO - 21:50:12: | n_components | The number of components of the gaussian mixture. | integer |
INFO - 21:50:12: | transformer | The strategies to transform the variables. the values are instances of | null |
INFO - 21:50:12: | | :class:`.transformer` while the keys are the names of either the variables or the groups | |
INFO - 21:50:12: | | of variables, e.g. "inputs" or "outputs" in the case of the regression algorithms. if a | |
INFO - 21:50:12: | | group is specified, the :class:`.transformer` will be applied to all the variables of this | |
INFO - 21:50:12: | | group. if none, do not transform the variables. | |
INFO - 21:50:12: | var_names | The names of the variables. if none, consider all variables mentioned in the learning | null |
INFO - 21:50:12: | | dataset. | |
INFO - 21:50: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 None, do not transform the variables.', 'type': 'null'}, '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']}
Create clustering model¶
iris = load_dataset("IrisDataset")
model = create_clustering_model("KMeans", data=iris, n_clusters=3)
model.learn()
print(model)
Out:
KMeans(n_clusters=3, random_state=0, var_names=None)
built from 150 learning samples
Total running time of the script: ( 0 minutes 0.046 seconds)