8000 DOC speed up example plot_digits_pipe.py (#21728) · samronsin/scikit-learn@0bb859f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bb859f

Browse files
ArthDhsamronsin
authored andcommitted
DOC speed up example plot_digits_pipe.py (scikit-learn#21728)
* Updated plot_digits_pipe * Updated plot_digits_pipe with StandardScaler preprocessing
1 parent 46cd34b commit 0bb859f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/compose/plot_digits_pipe.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@
2424
from sklearn.linear_model import LogisticRegression
2525
from sklearn.pipeline import Pipeline
2626
from sklearn.model_selection import GridSearchCV
27-
27+
from sklearn.preprocessing import StandardScaler
2828

2929
# Define a pipeline to search for the best combination of PCA truncation
3030
# and classifier regularization.
3131
pca = PCA()
32+
# Define a Standard Scaler to normalize inputs
33+
scaler = StandardScaler()
34+
3235
# set the tolerance to a large value to make the example faster
3336
logistic = LogisticRegression(max_iter=10000, tol=0.1)
34-
pipe = Pipeline(steps=[("pca", pca), ("logistic", logistic)])
37+
pipe = Pipeline(steps=[("scaler", scaler), ("pca", pca), ("logistic", logistic)])
3538

3639
X_digits, y_digits = datasets.load_digits(return_X_y=True)
37-
3840
# Parameters of pipelines can be set using ‘__’ separated parameter names:
3941
param_grid = {
40-
"pca__n_components": [5, 15, 30, 45, 64],
42+
"pca__n_components": [5, 15, 30, 45, 60],
4143
"logistic__C": np.logspace(-4, 4, 4),
4244
}
4345
search = GridSearchCV(pipe, param_grid, n_jobs=2)

0 commit comments

Comments
 (0)
0