.. 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 30-47 .. code-block:: default from __future__ import division, unicode_literals from gemseo.api import ( configure_logger, create_design_space, create_discipline, create_scenario, ) from gemseo.mlearning.api import ( create_regression_model, get_regression_models, get_regression_options, ) configure_logger() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 48-50 Get available regression models ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: default print(get_regression_models()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['GaussianProcessRegression', 'LinearRegression', 'MixtureOfExperts', 'PCERegression', 'PolynomialRegression', 'RBFRegression', 'RandomForestRegressor'] .. GENERATED FROM PYTHON SOURCE LINES 53-55 Get regression model options ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default print(get_regression_options("GaussianProcessRegression")) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'$schema': 'http://json-schema.org/schema#', 'type': 'object', 'properties': {'transformer': {'type': 'null'}, 'input_names': {'type': 'null'}, 'output_names': {'type': 'null'}, 'kernel': {'description': 'The kernel function. If None, use a ``Matern(2.5)``.', 'type': 'null'}, 'alpha': {'description': 'The nugget effect to regularize the model.', 'type': 'number'}, 'optimizer': {'description': 'The optimization algorithm to find the hyperparameters.', '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 58-60 Create regression model ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-80 .. code-block:: default expressions_dict = {"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_dict=expressions_dict ) 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) discipline.set_cache_policy(discipline.MEMORY_FULL_CACHE) scenario = create_scenario( [discipline], "DisciplinaryOpt", "y_1", design_space, scenario_type="DOE" ) scenario.execute({"algo": "fullfact", "n_samples": 9}) dataset = discipline.cache.export_to_dataset() model = create_regression_model("LinearRegression", data=dataset) model.learn() print(model) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 09:23:13: INFO - 09:23:13: *** Start DOE Scenario execution *** INFO - 09:23:13: DOEScenario INFO - 09:23:13: Disciplines: func INFO - 09:23:13: MDOFormulation: DisciplinaryOpt INFO - 09:23:13: Algorithm: fullfact INFO - 09:23:13: Optimization problem: INFO - 09:23:13: Minimize: y_1(x_1, x_2) INFO - 09:23:13: With respect to: x_1, x_2 INFO - 09:23:13: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 9 samples: 3 INFO - 09:23:13: Final number of samples for DOE = 9 vs 9 requested INFO - 09:23:13: DOE sampling: 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 `_