8000 DOC Add user guide for permutation_test_score by lucyleeow · Pull Request #18055 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC Add user guide for permutation_test_score #18055

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 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions doc/modules/cross_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,63 @@ Cross validation and model selection
Cross validation iterators can also be used to directly perform model
selection using Grid Search for the optimal hyperparameters of the
model. This is the topic of the next section: :ref:`grid_search`.

.. _permutation_test_score:

Permutation test score
======================

:func:`~sklearn.model_selection.permutation_test_score` offers another way
to evaluate the performance of classifiers. It provides a permutation-based
p-value, which represents how likely an observed performance of the
classifier would be obtained by chance. The null hypothesis in this test is
that the classifier fails to leverage any statistical dependency between the
features and the labels to make correct predictions on left out data.
:func:`~sklearn.model_selection.permutation_test_score` generates a null
distribution by calculating `n_permutations` different permutations of the
data. In each permutation the labels are randomly shuffled, thereby removing
any dependency between the features and the labels. The p-value output
is the fraction of permutations for which the average cross-validation score
obtained by the model is better than the cross-validation score obtained by
the model using the original data. For reliable results ``n_permutations``
should typically be larger than 100 and ``cv`` between 3-10 folds.

A low p-value provides evidence that the dataset contains real dependency
between features and labels and the classifier was able to utilize this
to obtain good results. A high p-value could be due to a lack of dependency
between features and labels (there is no difference in feature values between
the classes) or because the classifier was not able to use the dependency in
the data. In the latter case, using a more appropriate classifier that
is able to utilize the structure in the data, would result in a low
p-value.

Cross-validation provides information about how well a classifier generalizes,
specifically the range of expected errors of the classifier. However, a
classifier trained on a high dimensional dataset with no structure may still
perform better than expected on cross-validation, just by chance.
This can typically happen with small datasets with less than a few hundred
samples.
:func:`~sklearn.model_selection.permutation_test_score` provides information
on whether the classifier has found a real class structure and can help in
evaluating the performance of the classifier.

It is important to note that this test has been shown to produce low
p-values even if there is only weak structure in the data because in the
corresponding permutated datasets there is absolutely no structure. This
test is therefore only able to show when the model reliably outperforms
random guessing.

Finally, :func:`~sklearn.model_selection.permutation_test_score` is computed
using brute force and interally fits ``(n_permutations + 1) * n_cv`` models.
It is therefore only tractable with small datasets for which fitting an
individual model is very fast.

.. topic:: Examples

* :ref:`sphx_glr_auto_examples_feature_selection_plot_permutation_test_for_classification.py`

.. topic:: References:

* Ojala and Garriga. `Permutation Tests for Studying Classifier Performance
<http://www.jmlr.org/papers/volume11/ojala10a/ojala10a.pdf>`_.
J. Mach. Learn. Res. 2010.
2 changes: 2 additions & 0 deletions sklearn/model_selection/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ def permutation_test_score(estimator, X, y, *, groups=None, cv=None,
and targets or the estimator was not able to use the dependency to
give good predictions.

Read more in the :ref:`User Guide <permutation_test_score>`.

Parameters
----------
estimator : estimator object implementing 'fit'
Expand Down
0