.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_search_space.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_auto_examples_plot_search_space.py: Search space graph ==================================== mloptimizer provides a function to plot the search space of the optimization. .. GENERATED FROM PYTHON SOURCE LINES 6-17 .. code-block:: default from sklearn.tree import DecisionTreeClassifier from mloptimizer.domain.evaluation import kfold_stratified_score from mloptimizer.application.reporting.plots import plotly_search_space import plotly import os from sklearn.datasets import load_iris from mloptimizer.interfaces import HyperparameterSpaceBuilder, GeneticSearch from sklearn.model_selection import StratifiedKFold .. GENERATED FROM PYTHON SOURCE LINES 18-20 Load the iris dataset to obtain a vector of features X and a vector of labels y. Another dataset or a custom one can be used .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: default X, y = load_iris(return_X_y=True) .. GENERATED FROM PYTHON SOURCE LINES 23-26 Define the HyperparameterSpace, you can use the default hyperparameters for the machine learning model that you want to optimize. In this case we use the default hyperparameters for a DecisionTreeClassifier. Another dataset or a custom one can be used .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: default hyperparam_space = HyperparameterSpaceBuilder.get_default_space(estimator_class=DecisionTreeClassifier) .. GENERATED FROM PYTHON SOURCE LINES 29-30 The GeneticSearch class is used to optimize the hyperparameters of a machine learning model. .. GENERATED FROM PYTHON SOURCE LINES 30-38 .. code-block:: default cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42) opt = GeneticSearch( estimator_class=DecisionTreeClassifier, hyperparam_space=hyperparam_space, **{"generations": 30, "population_size": 100}, cv=cv ) .. GENERATED FROM PYTHON SOURCE LINES 39-40 To optimizer the classifier we need to call the fit method. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: default opt.fit(X, y) clf = opt.best_estimator_ .. rst-class:: sphx-glr-script-out .. code-block:: none Genetic execution: 0%| | 0/31 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_search_space.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_