-
Notifications
You must be signed in to change notification settings - Fork 1.3k
DOC improve instance hardness threshold user guide #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,12 +365,32 @@ and the output a 3 nearest neighbors classifier. The class can be used as:: | |
|
||
.. _instance_hardness_threshold: | ||
|
||
Additional undersampling techniques | ||
----------------------------------- | ||
|
||
Instance hardness threshold | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
:class:`InstanceHardnessThreshold` is a specific algorithm in which a | ||
classifier is trained on the data and the samples with lower probabilities are | ||
removed :cite:`smith2014instance`. The class can be used as:: | ||
**Instance Hardness** is a measure of how difficult it is to classify an instance or | ||
observation correctly. In other words, hard instances are observations that are hard to | ||
classify correctly. | ||
|
||
Fundamentally, instances that are hard to classify correctly are those for which the | ||
learning algorithm or classifier produces a low probability of predicting the correct | ||
class label. | ||
|
||
If we removed these hard instances from the dataset, the logic goes, we would help the | ||
classifier better identify the different classes :cite:`smith2014instance`. | ||
|
||
:class:`InstanceHardnessThreshold` trains a classifier on the data and then removes the | ||
samples with lower probabilities :cite:`smith2014instance`. Or in other words, it | ||
retains the observations with the higher class probabilities. | ||
|
||
In our implementation, :class:`InstanceHardnessThreshold` is (almost) a controlled | ||
under-sampling method: it will retain a specific number of observations of the target | ||
class(es), which is specified by the user (see caveat below). | ||
|
||
The class can be used as:: | ||
|
||
>>> from sklearn.linear_model import LogisticRegression | ||
>>> from imblearn.under_sampling import InstanceHardnessThreshold | ||
|
@@ -381,18 +401,18 @@ removed :cite:`smith2014instance`. The class can be used as:: | |
>>> print(sorted(Counter(y_resampled).items())) | ||
[(0, 64), (1, 64), (2, 64)] | ||
|
||
This class has 2 important parameters. ``estimator`` will accept any | ||
scikit-learn classifier which has a method ``predict_proba``. The classifier | ||
training is performed using a cross-validation and the parameter ``cv`` can set | ||
the number of folds to use. | ||
:class:`InstanceHardnessThreshold` has 2 important parameters. The parameter | ||
``estimator`` accepts any scikit-learn classifier with a method ``predict_proba``. | ||
This classifier will be used to identify the hard instances. The training is performed | ||
with cross-validation which can be specified through the parameter ``cv`. | ||
|
||
.. note:: | ||
|
||
:class:`InstanceHardnessThreshold` could almost be considered as a | ||
controlled under-sampling method. However, due to the probability outputs, it | ||
is not always possible to get a specific number of samples. | ||
is not always possible to get the specified number of samples. | ||
|
||
The figure below gives another examples on some toy data. | ||
The figure below shows examples of instance hardness undersampling on a toy dataset. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is FunctionSampler in the image below? random undersampling? Would be good to make it clear so the user knows what they are looking at in the plot |
||
.. image:: ./auto_examples/under-sampling/images/sphx_glr_plot_comparison_under_sampling_006.png | ||
:target: ./auto_examples/under-sampling/plot_comparison_under_sampling.html | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user guide is divided into controlled undersampling (RUS and nearmiss) and cleaning (all the others). I felt we needed another headline for IHT