8000 DOC use notebook-style for plot_svm_anova.py (#22779) · scikit-learn/scikit-learn@57e3523 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 57e3523

Browse files
JihaneBennisogrisellesteve
authored
DOC use notebook-style for plot_svm_anova.py (#22779)
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org> Co-authored-by: Loïc Estève <loic.esteve@ymail.com>
1 parent e593059 commit 57e3523

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

examples/svm/plot_svm_anova.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@
1010
1111
"""
1212

13+
# %%
14+
# Load some data to play with
15+
# ---------------------------
1316
import numpy as np
14-
import matplotlib.pyplot as plt
1517
from sklearn.datasets import load_iris
16-
from sklearn.feature_selection import SelectPercentile, chi2
17-
from sklearn.model_selection import cross_val_score
18-
from sklearn.pipeline 8000 import Pipeline
19-
from sklearn.preprocessing import StandardScaler
20-
from sklearn.svm import SVC
21-
2218

23-
# #############################################################################
24-
# Import some data to play with
2519
X, y = load_iris(return_X_y=True)
20+
2621
# Add non-informative features
27-
np.random.seed(0)
28-
X = np.hstack((X, 2 * np.random.random((X.shape[0], 36))))
22+
rng = np.random.RandomState(0)
23+
X = np.hstack((X, 2 * rng.random((X.shape[0], 36))))
24+
25+
# %%
26+
# Create the pipeline
27+
# -------------------
28+
from sklearn.pipeline import Pipeline
29+
from sklearn.feature_selection import SelectPercentile, chi2
30+
from sklearn.preprocessing import StandardScaler
31+
from sklearn.svm import SVC
2932

30-
# #############################################################################
3133
# Create a feature-selection transform, a scaler and an instance of SVM that we
3234
# combine together to have a full-blown estimator
35+
3336
clf = Pipeline(
3437
[
3538
("anova", SelectPercentile(chi2)),
@@ -38,8 +41,12 @@
3841
]
3942
)
4043

41-
# #############################################################################
44+
# %%
4245
# Plot the cross-validation score as a function of percentile of features
46+
# -----------------------------------------------------------------------
47+
import matplotlib.pyplot as plt
48+
from sklearn.model_selection import cross_val_score
49+
4350
score_means = list()
4451
score_stds = list()
4552
percentiles = (1, 3, 6, 10, 15, 20, 30, 40, 60, 80, 100)

0 commit comments

Comments
 (0)
0