.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mlearning/calibration/plot_calibration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_mlearning_calibration_plot_calibration.py: Calibration of a polynomial regression ====================================== .. GENERATED FROM PYTHON SOURCE LINES 24-34 .. code-block:: default from __future__ import annotations import matplotlib.pyplot as plt from gemseo.algos.design_space import DesignSpace from gemseo.api import configure_logger from gemseo.mlearning.core.calibration import MLAlgoCalibration from gemseo.mlearning.qual_measure.mse_measure import MSEMeasure from gemseo.problems.dataset.rosenbrock import RosenbrockDataset from matplotlib.tri import Triangulation .. GENERATED FROM PYTHON SOURCE LINES 35-37 Load the dataset ---------------- .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: default dataset = RosenbrockDataset(opt_naming=False, n_samples=25) .. GENERATED FROM PYTHON SOURCE LINES 40-42 Define the measure ------------------ .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: default configure_logger() test_dataset = RosenbrockDataset(opt_naming=False) measure_options = {"method": "test", "test_data": test_dataset} .. GENERATED FROM PYTHON SOURCE LINES 47-51 Calibrate the degree of the polynomial regression ------------------------------------------------- Define and execute the calibration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 51-67 .. code-block:: default calibration_space = DesignSpace() calibration_space.add_variable("degree", 1, "integer", 1, 10, 1) calibration = MLAlgoCalibration( "PolynomialRegressor", dataset, ["degree"], calibration_space, MSEMeasure, measure_options, ) calibration.execute({"algo": "fullfact", "n_samples": 10}) x_opt = calibration.optimal_parameters f_opt = calibration.optimal_criterion print("optimal degree:", x_opt["degree"][0]) print("optimal criterion:", f_opt) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 14:47:29: INFO - 14:47:29: *** Start DOEScenario execution *** INFO - 14:47:29: DOEScenario INFO - 14:47:29: Disciplines: MLAlgoAssessor INFO - 14:47:29: MDO formulation: DisciplinaryOpt INFO - 14:47:29: Optimization problem: INFO - 14:47:29: minimize criterion(degree) INFO - 14:47:29: with respect to degree INFO - 14:47:29: over the design space: INFO - 14:47:29: +--------+-------------+-------+-------------+---------+ INFO - 14:47:29: | name | lower_bound | value | upper_bound | type | INFO - 14:47:29: +--------+-------------+-------+-------------+---------+ INFO - 14:47:29: | degree | 1 | 1 | 10 | integer | INFO - 14:47:29: +--------+-------------+-------+-------------+---------+ INFO - 14:47:29: Solving optimization problem with algorithm fullfact: INFO - 14:47:29: ... 0%| | 0/10 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_calibration.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_