Classification API#

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

from __future__ import annotations

from gemseo import configure_logger
from gemseo import create_benchmark_dataset
from gemseo.mlearning import create_classification_model
from gemseo.mlearning import get_classification_models
from gemseo.mlearning import get_classification_options

configure_logger()
<RootLogger root (INFO)>

Get available classification models#

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

Get classification model options#

get_classification_options("KNNClassifier")
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|            Name           |                                        Description                                         |            Type           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
|        input_names        |                              The names of the input variables                              |           array           |
|        n_neighbors        |                                  The number of neighbors.                                  |          integer          |
|        output_names       |                             The names of the output variables                              |           array           |
|         parameters        |                                     Other parameters.                                      |           object          |
|        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.     |                           |
+---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 08:37:27: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 08:37:27: |            Name           |                                        Description                                         |            Type           |
    INFO - 08:37:27: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+
    INFO - 08:37:27: |        input_names        |                              The names of the input variables                              |           array           |
    INFO - 08:37:27: |        n_neighbors        |                                  The number of neighbors.                                  |          integer          |
    INFO - 08:37:27: |        output_names       |                             The names of the output variables                              |           array           |
    INFO - 08:37:27: |         parameters        |                                     Other parameters.                                      |           object          |
    INFO - 08:37:27: |        transformer        |          The strategies to transform the variables.  the values are instances of           |           object          |
    INFO - 08:37:27: |                           |   :class:`.basetransformer` while the keys are the names of either the variables or the    |                           |
    INFO - 08:37:27: |                           |   groups of variables, e.g. ``"inputs"`` or ``"outputs"`` in the case of the regression    |                           |
    INFO - 08:37:27: |                           | algorithms. if a group is specified, the :class:`.basetransformer` will be applied to all  |                           |
    INFO - 08:37:27: |                           |     the variables of this group. if :attr:`.identity`, do not transform the variables.     |                           |
    INFO - 08:37:27: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+

{'additionalProperties': False, 'description': 'The settings of the k-nearest neighbors classification algorithm.', 'properties': {'transformer': {'description': 'The strategies to transform the variables.\n\nThe values are instances of :class:`.BaseTransformer`\nwhile the keys are the names of\neither the variables\nor the groups of variables,\ne.g. ``"inputs"`` or ``"outputs"``\nin the case of the regression algorithms.\nIf a group is specified,\nthe :class:`.BaseTransformer` will be applied\nto all the variables of this group.\nIf :attr:`.IDENTITY`, do not transform the variables.', 'title': 'Transformer', 'type': 'object'}, 'parameters': {'description': 'Other parameters.', 'title': 'Parameters', 'type': 'object'}, 'input_names': {'default': [], 'description': 'The names of the input variables', 'items': {'type': 'string'}, 'title': 'Input Names', 'type': 'array'}, 'output_names': {'default': [], 'description': 'The names of the output variables', 'items': {'type': 'string'}, 'title': 'Output Names', 'type': 'array'}, 'n_neighbors': {'default': 5, 'description': 'The number of neighbors.', 'exclusiveMinimum': 0, 'title': 'N Neighbors', 'type': 'integer'}}, 'title': 'KNNClassifier_Settings', 'type': 'object'}

Create classification model#

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

model = create_classification_model("KNNClassifier", data=iris)
model.learn()
model
KNNClassifier(input_names=(), n_neighbors=5, output_names=(), parameters={}, transformer={'inputs': <gemseo.mlearning.transformers.scaler.min_max_scaler.MinMaxScaler object at 0x7f6dfa960ee0>})
  • based on the scikit-learn library
  • built from 150 learning samples


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

Gallery generated by Sphinx-Gallery