Classification API

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

from __future__ import annotations

from gemseo.api import configure_logger
from gemseo.api import load_dataset
from gemseo.mlearning.api import create_classification_model
from gemseo.mlearning.api import get_classification_models
from gemseo.mlearning.api import get_classification_options

configure_logger()
<RootLogger root (INFO)>

Get available classification models

print(get_classification_models())
['KNNClassifier', 'RandomForestClassifier', 'SVMClassifier']

Get classification model options

print(get_classification_options("KNNClassifier"))
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|            Name           |                                        Description                                         |            Type           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|        input_names        |   The names of the input variables. if ``none``, consider all the input variables of the   |            null           |
|                           |                                     learning dataset.                                      |                           |
|        n_neighbors        |                                  The number of neighbors.                                  |          integer          |
|        output_names       |  The names of the output variables. if ``none``, consider all the output variables of the  |            null           |
|                           |                                     learning dataset.                                      |                           |
|        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.              |                           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 11:22:34: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 11:22:34: |            Name           |                                        Description                                         |            Type           |
    INFO - 11:22:34: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 11:22:34: |        input_names        |   The names of the input variables. if ``none``, consider all the input variables of the   |            null           |
    INFO - 11:22:34: |                           |                                     learning dataset.                                      |                           |
    INFO - 11:22:34: |        n_neighbors        |                                  The number of neighbors.                                  |          integer          |
    INFO - 11:22:34: |        output_names       |  The names of the output variables. if ``none``, consider all the output variables of the  |            null           |
    INFO - 11:22:34: |                           |                                     learning dataset.                                      |                           |
    INFO - 11:22:34: |        transformer        |           The strategies to transform the variables. the values are instances of           |           object          |
    INFO - 11:22:34: |                           |  :class:`.transformer` while the keys are the names of either the variables or the groups  |                           |
    INFO - 11:22:34: |                           | of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression algorithms. |                           |
    INFO - 11:22:34: |                           | if a group is specified, the :class:`.transformer` will be applied to all the variables of |                           |
    INFO - 11:22:34: |                           |             this group. if :attr:`.identity`, do not transform the variables.              |                           |
    INFO - 11:22:34: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
{'$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'}, 'input_names': {'description': 'The names of the input variables. If ``None``, consider all the input variables of the learning dataset.', 'type': 'null'}, 'output_names': {'description': 'The names of the output variables. If ``None``, consider all the output variables of the learning dataset.', 'type': 'null'}, 'n_neighbors': {'description': 'The number of neighbors.', 'type': 'integer'}}, 'required': ['n_neighbors', 'transformer']}

Create classification model

iris = load_dataset("IrisDataset", as_io=True)

model = create_classification_model("KNNClassifier", data=iris)
model.learn()

print(model)
KNNClassifier(n_neighbors=5)
   based on the scikit-learn library
   built from 150 learning samples

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

Gallery generated by Sphinx-Gallery