:orphan:

.. _general_examples:

General examples
----------------

General-purpose and introductory examples for the `imbalanced-learn` toolbox.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to use the ``ratio`` parameter in the different examples. It illustrated...">

.. only:: html

    .. figure:: /auto_examples/images/thumb/sphx_glr_plot_ratio_usage_thumb.png

        :ref:`sphx_glr_auto_examples_plot_ratio_usage.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/plot_ratio_usage
.. raw:: html

    <div style='clear:both'></div>

.. _realword_examples:

Examples based on real world datasets
-------------------------------------

Examples which use real-word dataset.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Some balancing methods allow for balancing dataset with multiples classes. We provide an exampl...">

.. only:: html

    .. figure:: /auto_examples/applications/images/thumb/sphx_glr_plot_multi_class_under_sampling_thumb.png

        :ref:`sphx_glr_auto_examples_applications_plot_multi_class_under_sampling.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/applications/plot_multi_class_under_sampling

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows how to balance the text data before to train a classifier.">

.. only:: html

    .. figure:: /auto_examples/applications/images/thumb/sphx_glr_plot_topic_classication_thumb.png

        :ref:`sphx_glr_auto_examples_applications_plot_topic_classication.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/applications/plot_topic_classication

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="In this face recognition example two faces are used from the LFW (Faces in the Wild) dataset. S...">

.. only:: html

    .. figure:: /auto_examples/applications/images/thumb/sphx_glr_plot_over_sampling_benchmark_lfw_thumb.png

        :ref:`sphx_glr_auto_examples_applications_plot_over_sampling_benchmark_lfw.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/applications/plot_over_sampling_benchmark_lfw
.. raw:: html

    <div style='clear:both'></div>

.. _combine_examples:

Examples using combine class methods
====================================

Combine methods mixed over- and under-sampling methods. Generally SMOTE is used for over-sampling while some cleaning methods (i.e., ENN and Tomek links) are used to under-sample.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the SMOTE + ENN method.">

.. only:: html

    .. figure:: /auto_examples/combine/images/thumb/sphx_glr_plot_smote_enn_thumb.png

        :ref:`sphx_glr_auto_examples_combine_plot_smote_enn.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/combine/plot_smote_enn

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the SMOTE + Tomek method.">

.. only:: html

    .. figure:: /auto_examples/combine/images/thumb/sphx_glr_plot_smote_tomek_thumb.png

        :ref:`sphx_glr_auto_examples_combine_plot_smote_tomek.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/combine/plot_smote_tomek

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows the effect of applying an under-sampling algorithms after SMOTE over-samplin...">

.. only:: html

    .. figure:: /auto_examples/combine/images/thumb/sphx_glr_plot_comparison_combine_thumb.png

        :ref:`sphx_glr_auto_examples_combine_plot_comparison_combine.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/combine/plot_comparison_combine
.. raw:: html

    <div style='clear:both'></div>

.. _dataset_examples:

Dataset examples
-----------------------

Examples concerning the :mod:`imblearn.datasets` module.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the make_imbalance function">

.. only:: html

    .. figure:: /auto_examples/datasets/images/thumb/sphx_glr_plot_make_imbalance_thumb.png

        :ref:`sphx_glr_auto_examples_datasets_plot_make_imbalance.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/datasets/plot_make_imbalance
.. raw:: html

    <div style='clear:both'></div>

.. _ensemble_examples:

Example using ensemble class methods
====================================

Under-sampling methods implies that samples of the majority class are lost during the balancing procedure.
Ensemble methods offer an alternative to use most of the samples.
In fact, an ensemble of balanced sets is created and used to later train any classifier.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the easy ensemble method.">

.. only:: html

    .. figure:: /auto_examples/ensemble/images/thumb/sphx_glr_plot_easy_ensemble_thumb.png

        :ref:`sphx_glr_auto_examples_ensemble_plot_easy_ensemble.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/ensemble/plot_easy_ensemble

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the balance cascade ensemble method.">

.. only:: html

    .. figure:: /auto_examples/ensemble/images/thumb/sphx_glr_plot_balance_cascade_thumb.png

        :ref:`sphx_glr_auto_examples_ensemble_plot_balance_cascade.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/ensemble/plot_balance_cascade

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example shows the benefit of balancing the training set when using a bagging classifier. `...">

.. only:: html

    .. figure:: /auto_examples/ensemble/images/thumb/sphx_glr_plot_comparison_bagging_classifier_thumb.png

        :ref:`sphx_glr_auto_examples_ensemble_plot_comparison_bagging_classifier.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/ensemble/plot_comparison_bagging_classifier
.. raw:: html

    <div style='clear:both'></div>

.. _evaluation_examples:

Evaluation examples
-------------------

Examples illustrating how classification using imbalanced dataset can be done.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Specific metrics have been developed to evaluate classifier which has been trained using imbala...">

.. only:: html

    .. figure:: /auto_examples/evaluation/images/thumb/sphx_glr_plot_classification_report_thumb.png

        :ref:`sphx_glr_auto_examples_evaluation_plot_classification_report.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/evaluation/plot_classification_report

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Specific metrics have been developed to evaluate classifier which has been trained using imbala...">

.. only:: html

    .. figure:: /auto_examples/evaluation/images/thumb/sphx_glr_plot_metrics_thumb.png

        :ref:`sphx_glr_auto_examples_evaluation_plot_metrics.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/evaluation/plot_metrics
.. raw:: html

    <div style='clear:both'></div>

.. _model_selection_examples:

Model Selection
---------------

Examples related to the selection of balancing methods.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="In this example the impact of the SMOTE&#x27;s k_neighbors parameter is examined. In the plot you ca...">

.. only:: html

    .. figure:: /auto_examples/model_selection/images/thumb/sphx_glr_plot_validation_curve_thumb.png

        :ref:`sphx_glr_auto_examples_model_selection_plot_validation_curve.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/model_selection/plot_validation_curve
.. raw:: html

    <div style='clear:both'></div>

.. _over_sampling_examples:

Example using over-sampling class methods
=========================================

Data balancing can be performed by over-sampling such that new samples are generated in the minority class to reach a given balancing ratio.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates how a new sample is generated taking into account the neighbourhood of...">

.. only:: html

    .. figure:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_illustration_generation_sample_thumb.png

        :ref:`sphx_glr_auto_examples_over-sampling_plot_illustration_generation_sample.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/over-sampling/plot_illustration_generation_sample

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the Adaptive Synthetic Sampling Approach for Imbalanced Learning ADASYN meth...">

.. only:: html

    .. figure:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_adasyn_thumb.png

        :ref:`sphx_glr_auto_examples_over-sampling_plot_adasyn.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/over-sampling/plot_adasyn

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the random over-sampling method.">

.. only:: html

    .. figure:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_random_over_sampling_thumb.png

        :ref:`sphx_glr_auto_examples_over-sampling_plot_random_over_sampling.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/over-sampling/plot_random_over_sampling

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the SMOTE method and its variant.">

.. only:: html

    .. figure:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_smote_thumb.png

        :ref:`sphx_glr_auto_examples_over-sampling_plot_smote.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/over-sampling/plot_smote

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The following example attends to make a qualitative comparison between the different over-sampl...">

.. only:: html

    .. figure:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_comparison_over_sampling_thumb.png

        :ref:`sphx_glr_auto_examples_over-sampling_plot_comparison_over_sampling.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/over-sampling/plot_comparison_over_sampling
.. raw:: html

    <div style='clear:both'></div>

.. _pipeline_examples:

Pipeline examples
=================

Example of how to use the a pipeline to include under-sampling with `scikit-learn` estimators.


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An example of the Pipeline object working with transformers and resamplers.">

.. only:: html

    .. figure:: /auto_examples/pipeline/images/thumb/sphx_glr_plot_pipeline_classification_thumb.png

        :ref:`sphx_glr_auto_examples_pipeline_plot_pipeline_classification.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/pipeline/plot_pipeline_classification
.. raw:: html

    <div style='clear:both'></div>

.. _under_sampling_examples:

Example using under-sampling class methods
==========================================

Under-sampling refers to the process of reducing the number of samples in the majority classes.
The implemented methods can be categorized into 2 groups: (i) fixed under-sampling and (ii) cleaning under-sampling.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the Tomek links method. ">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_tomek_links_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_tomek_links.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_tomek_links

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the one-sided selection method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_one_sided_selection_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_one_sided_selection.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_one_sided_selection

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the random under-sampling method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_random_under_sampler_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_random_under_sampler.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_random_under_sampler

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the neighbourhood cleaning rule method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_neighbourhood_cleaning_rule_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_neighbourhood_cleaning_rule.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_neighbourhood_cleaning_rule

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the condensed nearest-neighbour method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_condensed_nearest_neighbour_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_condensed_nearest_neighbour.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_condensed_nearest_neighbour

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the nearmiss 1 &amp; 2 &amp; 3 method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_nearmiss_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_nearmiss.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_nearmiss

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the instance hardness threshold method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_instance_hardness_threshold_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_instance_hardness_threshold.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_instance_hardness_threshold

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates what is a Tomek link.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_illustration_tomek_links_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_illustration_tomek_links.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_illustration_tomek_links

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the cluster centroids method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_cluster_centroids_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_cluster_centroids.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_cluster_centroids

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An illustration of the ENN, RENN, and All-KNN method.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_enn_renn_allknn_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_enn_renn_allknn.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_enn_renn_allknn

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates the different way of selecting example in NearMiss.">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_illustration_nearmiss_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_illustration_nearmiss.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_illustration_nearmiss

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The following example attends to make a qualitative comparison between the different under-samp...">

.. only:: html

    .. figure:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_comparison_under_sampling_thumb.png

        :ref:`sphx_glr_auto_examples_under-sampling_plot_comparison_under_sampling.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /auto_examples/under-sampling/plot_comparison_under_sampling
.. raw:: html

    <div style='clear:both'></div>



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

    :download:`Download all examples in Python source code: auto_examples_python.zip <//home/lemaitre/Documents/code/toolbox/imbalanced-learn/doc/auto_examples/auto_examples_python.zip>`



  .. container:: sphx-glr-download

    :download:`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip <//home/lemaitre/Documents/code/toolbox/imbalanced-learn/doc/auto_examples/auto_examples_jupyter.zip>`

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
