Skip to content

Commit 483fafe

Browse files
authored
DOC show usage of __ in Pipeline and FeatureUnion (scikit-learn#26661)
1 parent b88b539 commit 483fafe

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

sklearn/pipeline.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ class Pipeline(_BaseComposition):
131131
>>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])
132132
>>> # The pipeline can be used as any other estimator
133133
>>> # and avoids leaking the test set into the train set
134-
>>> pipe.fit(X_train, y_train)
135-
Pipeline(steps=[('scaler', StandardScaler()), ('svc', SVC())])
136-
>>> pipe.score(X_test, y_test)
134+
>>> pipe.fit(X_train, y_train).score(X_test, y_test)
137135
0.88
136+
>>> # An estimator's parameter can be set using '__' syntax
137+
>>> pipe.set_params(svc__C=10).fit(X_train, y_train).score(X_test, y_test)
138+
0.76
138139
"""
139140

140141
# BaseEstimator interface
@@ -1051,6 +1052,10 @@ class FeatureUnion(TransformerMixin, _BaseComposition):
10511052
>>> union.fit_transform(X)
10521053
array([[ 1.5 , 3.0..., 0.8...],
10531054
[-1.5 , 5.7..., -0.4...]])
1055+
>>> # An estimator's parameter can be set using '__' syntax
1056+
>>> union.set_params(pca__n_components=1).fit_transform(X)
1057+
array([[ 1.5 , 3.0...],
1058+
[-1.5 , 5.7...]])
10541059
"""
10551060

10561061
_required_parameters = ["transformer_list"]
@@ -1362,11 +1367,12 @@ def __getitem__(self, name):
13621367

13631368

13641369
def make_union(*transformers, n_jobs=None, verbose=False):
1365-
"""Construct a FeatureUnion from the given transformers.
1370+
"""Construct a :class:`FeatureUnion` from the given transformers.
13661371
1367-
This is a shorthand for the FeatureUnion constructor; it does not require,
1368-
and does not permit, naming the transformers. Instead, they will be given
1369-
names automatically based on their types. It also does not allow weighting.
1372+
This is a shorthand for the :class:`FeatureUnion` constructor; it does not
1373+
require, and does not permit, naming the transformers. Instead, they will
1374+
be given names automatically based on their types. It also does not allow
1375+
weighting.
13701376
13711377
Parameters
13721378
----------

0 commit comments

Comments
 (0)