.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/datasets/plot_shifted_dataset_regression.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_datasets_plot_shifted_dataset_regression.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_datasets_plot_shifted_dataset_regression.py:


Plot dataset source domain and shifted target domain
====================================================

This illustrates the :func:`~skada.datasets.make_shifted_dataset`
dataset generator. Each method consists of generating source data
and shifted target data. We illustrate here:
covariate shift, target shift, concept drift, and sample bias.
See detailed description of each shift in [1]_.

.. [1] Moreno-Torres, J. G., Raeder, T., Alaiz-Rodriguez,
       R., Chawla, N. V., and Herrera, F. (2012).
       A unifying view on dataset shift in classification.
       Pattern recognition, 45(1):521-530.

.. GENERATED FROM PYTHON SOURCE LINES 16-21

.. code-block:: Python


    # Author: Ruben Bueno <ruben.bueno@polytechnique.edu>
    #
    # License: BSD 3-Clause








.. GENERATED FROM PYTHON SOURCE LINES 22-28

.. code-block:: Python


    import matplotlib.pyplot as plt

    from skada import source_target_split
    from skada.datasets import make_shifted_datasets








.. GENERATED FROM PYTHON SOURCE LINES 29-87

.. code-block:: Python



    def plot_shifted_dataset(shift, random_state=42):
        """Plot source and shifted target data for a given type of shift.

        The possible shifts are 'covariate_shift', 'target_shift',
        'concept_drift' or 'subspace'.

        We use here the same random seed for multiple calls to
        ensure same distributions.
        """
        X, y, sample_domain = make_shifted_datasets(
            n_samples_source=20,
            n_samples_target=20,
            shift=shift,
            noise=0.3,
            label="regression",
            random_state=random_state,
        )
        X_source, X_target, y_source, y_target = source_target_split(
            X, y, sample_domain=sample_domain
        )

        fig, (ax1, ax2) = plt.subplots(1, 2, sharex="row", sharey="row", figsize=(8, 4))
        fig.suptitle(shift.replace("_", " ").title(), fontsize=14)
        plt.subplots_adjust(bottom=0.15)
        ax1.scatter(
            X_source[:, 0],
            X_source[:, 1],
            c=y_source,
            vmax=max(y),
            alpha=0.5,
            cmap="autumn",
        )
        ax1.set_title("Source data")
        ax1.set_xlabel("Feature 1")
        ax1.set_ylabel("Feature 2")

        s = ax2.scatter(
            X_target[:, 0],
            X_target[:, 1],
            c=y_target,
            vmax=max(y),
            alpha=0.5,
            cmap="autumn",
        )
        ax2.set_title("Target data")
        ax2.set_xlabel("Feature 1")
        ax2.set_ylabel("Feature 2")

        fig.subplots_adjust(right=0.8)
        cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.80])
        cb = fig.colorbar(s, cax=cbar_ax)
        cb.set_label("y-value")

        plt.show()









.. GENERATED FROM PYTHON SOURCE LINES 88-91

.. code-block:: Python


    for shift in ["covariate_shift", "target_shift", "concept_drift", "subspace"]:
        plot_shifted_dataset(shift)



.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_001.png
         :alt: Covariate Shift, Source data, Target data
         :srcset: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_002.png
         :alt: Target Shift, Source data, Target data
         :srcset: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_002.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_003.png
         :alt: Concept Drift, Source data, Target data
         :srcset: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_003.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_004.png
         :alt: Subspace, Source data, Target data
         :srcset: /auto_examples/datasets/images/sphx_glr_plot_shifted_dataset_regression_004.png
         :class: sphx-glr-multi-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.599 seconds)


.. _sphx_glr_download_auto_examples_datasets_plot_shifted_dataset_regression.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_shifted_dataset_regression.ipynb <plot_shifted_dataset_regression.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_shifted_dataset_regression.py <plot_shifted_dataset_regression.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_shifted_dataset_regression.zip <plot_shifted_dataset_regression.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_