.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mlearning/regression_model/plot_regression_api.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_regression_model_plot_regression_api.py: API === Here are some examples of the machine learning API applied to regression models. .. GENERATED FROM PYTHON SOURCE LINES 28-39 .. code-block:: default from gemseo.api import configure_logger from gemseo.api import create_design_space from gemseo.api import create_discipline from gemseo.api import create_scenario from gemseo.mlearning.api import create_regression_model from gemseo.mlearning.api import get_regression_models from gemseo.mlearning.api import get_regression_options configure_logger() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-42 Get available regression models ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: default print(get_regression_models()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['GaussianProcessRegressor', 'LinearRegressor', 'MOERegressor', 'PCERegressor', 'PolynomialRegressor', 'RBFRegressor', 'RandomForestRegressor'] .. GENERATED FROM PYTHON SOURCE LINES 45-47 Get regression model options ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: default print(get_regression_options("GaussianProcessRegressor")) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ | Name | Description | Type | +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ | alpha | The nugget effect to regularize the model. | number | | bounds | The lower and upper bounds of the parameter length scales when ``kernel`` is ``none``. | null | | | either a unique lower-upper pair common to all the inputs or lower-upper pairs for some of | | | | them. when ``bounds`` is ``none`` or when an input has no pair, the lower bound is 0.01 | | | | and the upper bound is 100. | | | input_names | The names of the input variables. if ``none``, consider all the input variables of the | null | | | learning dataset. | | | kernel | The kernel specifying the covariance model. if ``none``, use a matérn(2.5). | null | | n_restarts_optimizer | The number of restarts of the optimizer. | integer | | optimizer | The optimization algorithm to find the parameter length scales. | string | | output_names | The names of the output variables. if ``none``, consider all the output variables of the | null | | | learning dataset. | | | random_state | The seed used to initialize the centers. if none, the random number generator is the | null | | | randomstate instance used by `numpy.random`. | | | transformer | The strategies to transform the variables. the values are instances of | null | | | :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 none, do not transform the variables. | | +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ INFO - 10:06:44: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ INFO - 10:06:44: | Name | Description | Type | INFO - 10:06:44: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ INFO - 10:06:44: | alpha | The nugget effect to regularize the model. | number | INFO - 10:06:44: | bounds | The lower and upper bounds of the parameter length scales when ``kernel`` is ``none``. | null | INFO - 10:06:44: | | either a unique lower-upper pair common to all the inputs or lower-upper pairs for some of | | INFO - 10:06:44: | | them. when ``bounds`` is ``none`` or when an input has no pair, the lower bound is 0.01 | | INFO - 10:06:44: | | and the upper bound is 100. | | INFO - 10:06:44: | input_names | The names of the input variables. if ``none``, consider all the input variables of the | null | INFO - 10:06:44: | | learning dataset. | | INFO - 10:06:44: | kernel | The kernel specifying the covariance model. if ``none``, use a matérn(2.5). | null | INFO - 10:06:44: | n_restarts_optimizer | The number of restarts of the optimizer. | integer | INFO - 10:06:44: | optimizer | The optimization algorithm to find the parameter length scales. | string | INFO - 10:06:44: | output_names | The names of the output variables. if ``none``, consider all the output variables of the | null | INFO - 10:06:44: | | learning dataset. | | INFO - 10:06:44: | random_state | The seed used to initialize the centers. if none, the random number generator is the | null | INFO - 10:06:44: | | randomstate instance used by `numpy.random`. | | INFO - 10:06:44: | transformer | The strategies to transform the variables. the values are instances of | null | INFO - 10:06:44: | | :class:`.transformer` while the keys are the names of either the variables or the groups | | INFO - 10:06:44: | | of variables, e.g. "inputs" or "outputs" in the case of the regression algorithms. if a | | INFO - 10:06:44: | | group is specified, the :class:`.transformer` will be applied to all the variables of this | | INFO - 10:06:44: | | group. if none, do not transform the variables. | | INFO - 10:06:44: +---------------------------+--------------------------------------------------------------------------------------------+---------------------------+ {'$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 None, do not transform the variables.', 'type': 'null'}, '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'}, 'kernel': {'description': 'The kernel specifying the covariance model. If ``None``, use a Matérn(2.5).', 'type': 'null'}, 'bounds': {'description': 'The lower and upper bounds of the parameter length scales when ``kernel`` is ``None``. Either a unique lower-upper pair common to all the inputs or lower-upper pairs for some of them. When ``bounds`` is ``None`` or when an input has no pair, the lower bound is 0.01 and the upper bound is 100.', 'type': 'null'}, 'alpha': {'description': 'The nugget effect to regularize the model.', 'type': 'number'}, 'optimizer': {'description': 'The optimization algorithm to find the parameter length scales.', 'type': 'string'}, 'n_restarts_optimizer': {'description': 'The number of restarts of the optimizer.', 'type': 'integer'}, 'random_state': {'description': 'The seed used to initialize the centers. If None, the random number generator is the RandomState instance used by `numpy.random`.', 'type': 'null'}}, 'required': ['alpha', 'n_restarts_optimizer', 'optimizer']} .. GENERATED FROM PYTHON SOURCE LINES 50-52 Create regression model ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 52-71 .. code-block:: default expressions = {"y_1": "1+2*x_1+3*x_2", "y_2": "-1-2*x_1-3*x_2"} discipline = create_discipline( "AnalyticDiscipline", name="func", expressions=expressions ) design_space = create_design_space() design_space.add_variable("x_1", l_b=0.0, u_b=1.0) design_space.add_variable("x_2", l_b=0.0, u_b=1.0) scenario = create_scenario( [discipline], "DisciplinaryOpt", "y_1", design_space, scenario_type="DOE" ) scenario.execute({"algo": "fullfact", "n_samples": 9}) dataset = scenario.export_to_dataset(opt_naming=False) model = create_regression_model("LinearRegressor", data=dataset) model.learn() print(model) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 10:06:44: INFO - 10:06:44: *** Start DOEScenario execution *** INFO - 10:06:44: DOEScenario INFO - 10:06:44: Disciplines: func INFO - 10:06:44: MDO formulation: DisciplinaryOpt INFO - 10:06:44: Optimization problem: INFO - 10:06:44: minimize y_1(x_1, x_2) INFO - 10:06:44: with respect to x_1, x_2 INFO - 10:06:44: over the design space: INFO - 10:06:44: +------+-------------+-------+-------------+-------+ INFO - 10:06:44: | name | lower_bound | value | upper_bound | type | INFO - 10:06:44: +------+-------------+-------+-------------+-------+ INFO - 10:06:44: | x_1 | 0 | None | 1 | float | INFO - 10:06:44: | x_2 | 0 | None | 1 | float | INFO - 10:06:44: +------+-------------+-------+-------------+-------+ INFO - 10:06:44: Solving optimization problem with algorithm fullfact: INFO - 10:06:44: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 9 samples: 3 INFO - 10:06:44: Final number of samples for DOE = 9 vs 9 requested INFO - 10:06:44: ... 0%| | 0/9 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_regression_api.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_