
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/04-interpolation-based/02-plot_isi_multiclass_classification.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_04-interpolation-based_02-plot_isi_multiclass_classification.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_04-interpolation-based_02-plot_isi_multiclass_classification.py:


Multiclass classification using ISI
===================================

.. GENERATED FROM PYTHON SOURCE LINES 7-9

Imports
-------

.. GENERATED FROM PYTHON SOURCE LINES 9-23

.. code-block:: Python


    import matplotlib.pyplot as plt
    import pandas as pd
    import seaborn as sns

    from uniharmony import verbosity
    from uniharmony.datasets import make_multisite_classification
    from uniharmony.interpolation import IntraSiteInterpolation


    sns.set_theme(style="whitegrid")
    verbosity("warning")









.. GENERATED FROM PYTHON SOURCE LINES 24-26

Data generation
---------------

.. GENERATED FROM PYTHON SOURCE LINES 26-44

.. code-block:: Python


    X, y, sites = make_multisite_classification(
        n_classes=3,
        n_samples=1000,
        n_sites=2,
        n_features=2,
        # one value per class, one list per site.
        balance_per_site=[[0.3, 0.1, 0.6], [0.6, 0.1, 0.3]],
        signal_strength=0,
        random_state=23,
    )
    df = pd.DataFrame({"Target": y, "Site": sites})
    plt.figure(figsize=[10, 6])
    plt.title("Unbalanced classes by site")
    sns.countplot(df, x="Target", hue="Site")
    plt.grid(axis="y", color="black", alpha=0.5, linestyle="--")





.. image-sg:: /auto_examples/04-interpolation-based/images/sphx_glr_02-plot_isi_multiclass_classification_001.png
   :alt: Unbalanced classes by site
   :srcset: /auto_examples/04-interpolation-based/images/sphx_glr_02-plot_isi_multiclass_classification_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    2026-05-18 13:27:57 [warning  ] signal_strength is 0. Adding a delta (1e-6) to signal_strength to avoid degenerate data.




.. GENERATED FROM PYTHON SOURCE LINES 45-47

Harmonisation
-------------

.. GENERATED FROM PYTHON SOURCE LINES 47-51

.. code-block:: Python


    isi = IntraSiteInterpolation()
    X_r, y_r = isi.fit_resample(X, y, sites=sites)








.. GENERATED FROM PYTHON SOURCE LINES 52-54

Plotting
--------

.. GENERATED FROM PYTHON SOURCE LINES 54-67

.. code-block:: Python


    df = pd.DataFrame(
        {
            "Target": y_r,
            "Site": isi.sites_resampled_,
            "Feature 1": X_r[:, 0],
            "Feature 2": X_r[:, 1],
        }
    )
    plt.figure(figsize=[10, 6])
    plt.title("Balanced classes by site")
    sns.countplot(df, x="Target", hue="Site")
    plt.grid(axis="y", color="black", alpha=0.5, linestyle="--")



.. image-sg:: /auto_examples/04-interpolation-based/images/sphx_glr_02-plot_isi_multiclass_classification_002.png
   :alt: Balanced classes by site
   :srcset: /auto_examples/04-interpolation-based/images/sphx_glr_02-plot_isi_multiclass_classification_002.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_auto_examples_04-interpolation-based_02-plot_isi_multiclass_classification.py:

.. only:: html

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

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

      :download:`Download Jupyter notebook: 02-plot_isi_multiclass_classification.ipynb <02-plot_isi_multiclass_classification.ipynb>`

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

      :download:`Download Python source code: 02-plot_isi_multiclass_classification.py <02-plot_isi_multiclass_classification.py>`

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

      :download:`Download zipped: 02-plot_isi_multiclass_classification.zip <02-plot_isi_multiclass_classification.zip>`


.. only:: html

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

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