.. 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-35 .. code-block:: Python from __future__ import annotations from gemseo.datasets.io_dataset import IODataset .. GENERATED FROM PYTHON SOURCE LINES 36-38 First, we instantiate the :class:`.IODataset`: .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python dataset = IODataset() .. GENERATED FROM PYTHON SOURCE LINES 41-45 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 45-48 .. code-block:: Python 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 49-50 as well as another variable: .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python 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 54-56 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 56-64 .. code-block:: Python 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 65-67 Then, we can easily access the names of the input and output variables: .. GENERATED FROM PYTHON SOURCE LINES 67-68 .. code-block:: Python dataset.input_names, dataset.output_names .. rst-class:: sphx-glr-script-out .. code-block:: none (['a', 'b'], ['c']) .. GENERATED FROM PYTHON SOURCE LINES 69-70 and those of all variables: .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python dataset.variable_names .. rst-class:: sphx-glr-script-out .. code-block:: none ['a', 'b', 'c', 'x'] .. GENERATED FROM PYTHON SOURCE LINES 73-74 The :class:`.IODataset` provides also the number of samples: .. GENERATED FROM PYTHON SOURCE LINES 74-75 .. code-block:: Python dataset.n_samples .. rst-class:: sphx-glr-script-out .. code-block:: none 2 .. GENERATED FROM PYTHON SOURCE LINES 76-77 and the samples: .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: Python dataset.samples .. rst-class:: sphx-glr-script-out .. code-block:: none [0, 1] .. GENERATED FROM PYTHON SOURCE LINES 80-82 Lastly, we can get the input data as an :class:`.IODataset` view: .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: Python 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 85-86 and the same for the output data: .. GENERATED FROM PYTHON SOURCE LINES 86-87 .. code-block:: Python 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.028 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-jupyter :download:`Download Jupyter notebook: plot_io_dataset.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_io_dataset.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_