.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_example1.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_auto_examples_plot_example1.py: Example on 2-d data =================== .. GENERATED FROM PYTHON SOURCE LINES 7-11 .. code-block:: Python import openturns as ot import otsliced import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 12-13 Create 2-d data X and 1-d feature Y .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: Python N = 100 X = ot.Normal([0.0] * 2, [0.1] * 2).getSample(N) X += [[-i / (N - 1), 2 * i / (N - 1)] for i in range(N)] X = X - X.computeMean() f = ot.SymbolicFunction(["x1", "x2"], ["4*(x1+2*x2)+2"]) Y = f(X) + ot.Normal(0.0, 0.2).getSample(N) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Plot data .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python plt.scatter(X.getMarginal(0), X.getMarginal(1), c=Y) plt.xlabel('x1') plt.ylabel('x2') plt.axis('square') plt.title("2D colored Dataset") .. image-sg:: /auto_examples/images/sphx_glr_plot_example1_001.png :alt: 2D colored Dataset :srcset: /auto_examples/images/sphx_glr_plot_example1_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, '2D colored Dataset') .. GENERATED FROM PYTHON SOURCE LINES 29-30 Run the SIR algorithm .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python algo = otsliced.SlicedInverseRegression(X, Y) algo.run() transformation = algo.getResult().getTransformation() .. GENERATED FROM PYTHON SOURCE LINES 35-36 Show SIR direction .. GENERATED FROM PYTHON SOURCE LINES 36-44 .. code-block:: Python plt.scatter(X.getMarginal(0), X.getMarginal(1), c=Y) plt.xlabel('x1') plt.ylabel('x2') plt.axis('square') plt.title("First direction of SIR") dir_sir = algo.getResult().getDirections() plt.plot([-dir_sir[0, 0] * 30, dir_sir[0, 0] * 30], [-dir_sir[1, 0] * 30, dir_sir[1, 0] * 30], c='red') .. image-sg:: /auto_examples/images/sphx_glr_plot_example1_002.png :alt: First direction of SIR :srcset: /auto_examples/images/sphx_glr_plot_example1_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [] .. GENERATED FROM PYTHON SOURCE LINES 45-46 .. code-block:: Python plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.126 seconds) .. _sphx_glr_download_auto_examples_plot_example1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_example1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_example1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_example1.zip `