.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/dataset/creation/plot_io_dataset.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_examples_dataset_creation_plot_io_dataset.py: The input-output dataset ======================== The :class:`.IODataset` proposes two particular group names, namely :attr:`~.IODataset.INPUT_GROUP` and :attr:`~.IODataset.OUTPUT_GROUP`. This particular :class:`.Dataset` is useful for supervised machine learning and sensitivity analysis. .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: default from __future__ import annotations from gemseo.datasets.io_dataset import IODataset .. GENERATED FROM PYTHON SOURCE LINES 35-37 First, we instantiate the :class:`.IODataset`: .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: default dataset = IODataset() .. GENERATED FROM PYTHON SOURCE LINES 40-44 and add some input and output variables using the methods :meth:`~.IODataset.add_input_variable` and :meth:`~.IODataset.add_output_variable` that are based on :meth:`.Dataset.add_variable`: .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: default dataset.add_input_variable("a", [[1.0, 2.0], [4.0, 5.0]]) dataset.add_input_variable("b", [[3.0], [6.0]]) dataset.add_output_variable("c", [[-1.0], [-2.0]]) .. GENERATED FROM PYTHON SOURCE LINES 48-49 as well as another variable: .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default dataset.add_variable("x", [[10.0], [20.0]]) dataset .. raw:: html
GROUP inputs outputs parameters
VARIABLE a b c x
COMPONENT 0 1 0 0 0
0 1.0 2.0 3.0 -1.0 10.0
1 4.0 5.0 6.0 -2.0 20.0


.. GENERATED FROM PYTHON SOURCE LINES 53-55 We could also do the same with the methods :meth:`~.IODataset.add_input_group` and :meth:`~.IODataset.add_output_group`. .. GENERATED FROM PYTHON SOURCE LINES 55-63 .. code-block:: default dataset = IODataset() dataset.add_input_group( [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], ["a", "b"], {"a": 2, "b": 1} ) dataset.add_output_group([[-1.0], [-2.0]], ["c"]) dataset.add_variable("x", [[10.0], [20.0]]) dataset .. raw:: html
GROUP inputs outputs parameters
VARIABLE a b c x
COMPONENT 0 1 0 0 0
0 1.0 2.0 3.0 -1.0 10.0
1 4.0 5.0 6.0 -2.0 20.0


.. GENERATED FROM PYTHON SOURCE LINES 64-66 Then, we can easily access the names of the input and output variables: .. GENERATED FROM PYTHON SOURCE LINES 66-67 .. code-block:: default dataset.input_names, dataset.output_names .. rst-class:: sphx-glr-script-out .. code-block:: none (['a', 'b'], ['c']) .. GENERATED FROM PYTHON SOURCE LINES 68-69 and those of all variables: .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: default dataset.variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ['a', 'b', 'c', 'x'] .. GENERATED FROM PYTHON SOURCE LINES 72-73 The :class:`.IODataset` provides also the number of samples: .. GENERATED FROM PYTHON SOURCE LINES 73-74 .. code-block:: default dataset.n_samples .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 75-76 and the samples: .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: default dataset.samples .. rst-class:: sphx-glr-script-out .. code-block:: none [0, 1] .. GENERATED FROM PYTHON SOURCE LINES 79-81 Lastly, we can get the input data as an :class:`.IODataset` view: .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: default dataset.input_dataset .. raw:: html
GROUP inputs
VARIABLE a b
COMPONENT 0 1 0
0 1.0 2.0 3.0
1 4.0 5.0 6.0


.. GENERATED FROM PYTHON SOURCE LINES 84-85 and the same for the output data: .. GENERATED FROM PYTHON SOURCE LINES 85-86 .. code-block:: default dataset.output_dataset .. raw:: html
GROUP outputs
VARIABLE c
COMPONENT 0
0 -1.0
1 -2.0


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.034 seconds) .. _sphx_glr_download_examples_dataset_creation_plot_io_dataset.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_io_dataset.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_io_dataset.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_