:orphan:
.. _general_examples:
Examples
--------
General-purpose and introductory examples for the `imbalanced-learn` toolbox.
.. raw:: html
    
.. thumbnail-parent-div-open
.. thumbnail-parent-div-close
.. raw:: html
    
Examples showing API imbalanced-learn usage
-------------------------------------------
Examples that show some details regarding the API of imbalanced-learn.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/api/images/thumb/sphx_glr_plot_sampling_strategy_usage_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_api_plot_sampling_strategy_usage.py`
.. raw:: html
      
How to use sampling_strategy in imbalanced-learn
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
Examples based on real world datasets
-------------------------------------
Examples which use real-word dataset.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_plot_multi_class_under_sampling_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_plot_multi_class_under_sampling.py`
.. raw:: html
      
Multiclass classification with under-sampling
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_plot_topic_classication_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_plot_topic_classication.py`
.. raw:: html
      
Example of topic classification in text documents
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_plot_outlier_rejections_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_plot_outlier_rejections.py`
.. raw:: html
      
Customized sampler to implement an outlier rejections estimator
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_plot_over_sampling_benchmark_lfw_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_plot_over_sampling_benchmark_lfw.py`
.. raw:: html
      
Benchmark over-sampling methods in a face recognition task
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_porto_seguro_keras_under_sampling_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_porto_seguro_keras_under_sampling.py`
.. raw:: html
      
Porto Seguro: balancing samples in mini-batches with Keras
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/applications/images/thumb/sphx_glr_plot_impact_imbalanced_classes_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_applications_plot_impact_imbalanced_classes.py`
.. raw:: html
      
Fitting model on imbalanced datasets and how to fight bias
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
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
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/combine/images/thumb/sphx_glr_plot_comparison_combine_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_combine_plot_comparison_combine.py`
.. raw:: html
      
Compare sampler combining over- and under-sampling
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
Dataset examples
-----------------------
Examples concerning the :mod:`imblearn.datasets` module.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/datasets/images/thumb/sphx_glr_plot_make_imbalance_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_datasets_plot_make_imbalance.py`
.. raw:: html
      
Create an imbalanced dataset
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
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
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/ensemble/images/thumb/sphx_glr_plot_bagging_classifier_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_ensemble_plot_bagging_classifier.py`
.. raw:: html
      
Bagging classifiers using sampler
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/ensemble/images/thumb/sphx_glr_plot_comparison_ensemble_classifier_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_ensemble_plot_comparison_ensemble_classifier.py`
.. raw:: html
      
Compare ensemble classifiers using resampling
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
Evaluation examples
-------------------
Examples illustrating how classification using imbalanced dataset can be done.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/evaluation/images/thumb/sphx_glr_plot_classification_report_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_evaluation_plot_classification_report.py`
.. raw:: html
      
Evaluate classification by compiling a report
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/evaluation/images/thumb/sphx_glr_plot_metrics_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_evaluation_plot_metrics.py`
.. raw:: html
      
Metrics specific to imbalanced learning
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
Model Selection
---------------
Examples related to the selection of balancing methods.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/model_selection/images/thumb/sphx_glr_plot_instance_hardness_cv_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_model_selection_plot_instance_hardness_cv.py`
.. raw:: html
      
Distribute hard-to-classify datapoints over CV folds
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/model_selection/images/thumb/sphx_glr_plot_validation_curve_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_model_selection_plot_validation_curve.py`
.. raw:: html
      
Plotting Validation Curves
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
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
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_illustration_generation_sample_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_over-sampling_plot_illustration_generation_sample.py`
.. raw:: html
      
Sample generator used in SMOTE-like samplers
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_shrinkage_effect_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_over-sampling_plot_shrinkage_effect.py`
.. raw:: html
      
Effect of the shrinkage factor in random over-sampling
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/over-sampling/images/thumb/sphx_glr_plot_comparison_over_sampling_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_over-sampling_plot_comparison_over_sampling.py`
.. raw:: html
      
Compare over-sampling samplers
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
Pipeline examples
=================
Example of how to use the a pipeline to include under-sampling with `scikit-learn` estimators.
.. raw:: html
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/pipeline/images/thumb/sphx_glr_plot_pipeline_classification_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_pipeline_plot_pipeline_classification.py`
.. raw:: html
      
Usage of pipeline embedding samplers
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
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
    
.. thumbnail-parent-div-open
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_illustration_tomek_links_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_under-sampling_plot_illustration_tomek_links.py`
.. raw:: html
      
Illustration of the definition of a Tomek link
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_illustration_nearmiss_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_under-sampling_plot_illustration_nearmiss.py`
.. raw:: html
      
Sample selection in NearMiss
    
.. raw:: html
    
.. only:: html
  .. image:: /auto_examples/under-sampling/images/thumb/sphx_glr_plot_comparison_under_sampling_thumb.png
    :alt:
  :ref:`sphx_glr_auto_examples_under-sampling_plot_comparison_under_sampling.py`
.. raw:: html
      
Compare under-sampling samplers
    
.. thumbnail-parent-div-close
.. raw:: html
    
 
.. toctree::
   :hidden:
   :includehidden:
   /auto_examples/api/index.rst
   /auto_examples/applications/index.rst
   /auto_examples/combine/index.rst
   /auto_examples/datasets/index.rst
   /auto_examples/ensemble/index.rst
   /auto_examples/evaluation/index.rst
   /auto_examples/model_selection/index.rst
   /auto_examples/over-sampling/index.rst
   /auto_examples/pipeline/index.rst
   /auto_examples/under-sampling/index.rst
.. only:: html
  .. container:: sphx-glr-footer sphx-glr-footer-gallery
    .. container:: sphx-glr-download sphx-glr-download-python
      :download:`Download all examples in Python source code: auto_examples_python.zip `
    .. container:: sphx-glr-download sphx-glr-download-jupyter
      :download:`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip `
.. only:: html
 .. rst-class:: sphx-glr-signature
    `Gallery generated by Sphinx-Gallery `_