8000 DOC solve plotting issue in plot_permutation_test_for_classification … · rth/scikit-learn@8647634 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8647634

Browse files
authored
DOC solve plotting issue in plot_permutation_test_for_classification (scikit-learn#20637)
1 parent daec880 commit 8647634

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

examples/model_selection/plot_permutation_tests_for_classification.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>
1212
# Lucy Liu
1313
# License: BSD 3 clause
14-
#
14+
15+
# %%
1516
# Dataset
1617
# -------
1718
#
@@ -60,14 +61,16 @@
6061
from sklearn.model_selection import StratifiedKFold
6162
from sklearn.model_selection import permutation_test_score
6263

63-
clf = SVC(kernel='linear', random_state=7)
64+
clf = SVC(kernel="linear", random_state=7)
6465
cv = StratifiedKFold(2, shuffle=True, random_state=0)
6566

6667
score_iris, perm_scores_iris, pvalue_iris = permutation_test_score(
67-
clf, X, y, scoring="accuracy", cv=cv, n_permutations=1000)
68+
clf, X, y, scoring="accuracy", cv=cv, n_permutations=1000
69+
)
6870

6971
score_rand, perm_scores_rand, pvalue_rand = permutation_test_score(
70-
clf, X_rand, y, scoring="accuracy", cv=cv, n_permutations=1000)
72+
clf, X_rand, y, scoring="accuracy", cv=cv, n_permutations=1000
73+
)
7174

7275
# %%
7376
# Original data
@@ -87,10 +90,9 @@
8790
fig, ax = plt.subplots()
8891

8992
ax.hist(perm_scores_iris, bins=20, density=True)
90-
ax.axvline(score_iris, ls='--', color='r')
91-
score_label = (f"Score on original\ndata: {score_iris:.2f}\n"
92-
f"(p-value: {pvalue_iris:.3f})")
93-
ax.text(0.7, 260, score_label, fontsize=12)
93+
ax.axvline(score_iris, ls="--", color="r")
94+
score_label = f"Score on original\ndata: {score_iris:.2f}\n(p-value: {pvalue_iris:.3f})"
95+
ax.text(0.7, 10, score_label, fontsize=12)
9496
ax.set_xlabel("Accuracy score")
9597
_ = ax.set_ylabel("Probability")
9698

@@ -109,10 +111,9 @@
109111

110112
ax.hist(perm_scores_rand, bins=20, density=True)
111113
ax.set_xlim(0.13)
112-
ax.axvline(score_rand, ls='--', color='r')
113-
score_label = (f"Score on original\ndata: {score_rand:.2f}\n"
114-
f"(p-value: {pvalue_rand:.3f})")
115-
ax.text(0.14, 125, score_label, fontsize=12)
114+
ax.axvline(score_rand, ls="--", color="r")
115+
score_label = f"Score on original\ndata: {score_rand:.2f}\n(p-value: {pvalue_rand:.3f})"
116+
ax.text(0.14, 7.5, score_label, fontsize=12)
116117
ax.set_xlabel("Accuracy score")
117118
ax.set_ylabel("Probability")
118119
plt.show()

0 commit comments

Comments
 (0)
0