High-level functions#

The gemseo.mlearning package includes high-level functions to create classification models from model class names.

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)>

Available models#

Use the get_classification_models() to list the available model class names:

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

Available model options#

Use the get_classification_options() to get the options of a model from its class name:

get_classification_options("KNNClassifier", pretty_print=False)
{'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'}

See also

The functions get_classification_models() and get_classification_options() can be very useful for the developers. As a user, it may be easier to consult this page to find out about the different algorithms and their options.

Creation#

Given a training dataset, e.g.

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

use the create_classification_model() function to create a classification model from its class name and settings:

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

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

Gallery generated by Sphinx-Gallery