From 741d0bd75cb4bb208502b62bd6e22a4f00c2371f Mon Sep 17 00:00:00 2001 From: Juan Martin Loyola Date: Tue, 7 Sep 2021 23:26:02 -0300 Subject: [PATCH 1/6] Remove Pipeline from DOCSTRING_IGNORE_LIST --- maint_tools/test_docstrings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 69478c846a4a3..506338c122dab 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -52,7 +52,6 @@ "PassiveAggressiveClassifier", "PassiveAggressiveRegressor", "PatchExtractor", - "Pipeline", "PolynomialFeatures", "PowerTransformer", "QuadraticDiscriminantAnalysis", From 923ea40ab9cee8483f32256bb047e629fe4225cb Mon Sep 17 00:00:00 2001 From: Juan Martin Loyola Date: Tue, 7 Sep 2021 23:26:22 -0300 Subject: [PATCH 2/6] Fix numpydocs from Pipeline --- sklearn/pipeline.py | 51 +++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 9d4997686612b..35f016e20d0e2 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -173,9 +173,17 @@ def set_params(self, **kwargs): you can directly set the parameters of the estimators contained in `steps`. + Parameters + ---------- + **kwargs : dict + Parameters of this estimator or parameters of estimators contained + in `steps`. Parameters of the steps may be set using its name and + the parameter name separated by a '__'. + Returns ------- - self + self : object + Pipeline class instance. """ self._set_params("steps", **kwargs) return self @@ -266,6 +274,10 @@ def _estimator_type(self): @property def named_steps(self): + """Access the steps by name. + + Read-only attribute to access any step by given name. + Keys are steps names and values are the steps objects.""" # Use Bunch object to improve autocomplete return Bunch(**dict(self.steps)) @@ -349,7 +361,7 @@ def _fit(self, X, y=None, **fit_params_steps): return X def fit(self, X, y=None, **fit_params): - """Fit the model + """Fit the model. Fit all the transforms one after the other and transform the data, then fit the transformed data using the final estimator. @@ -372,7 +384,7 @@ def fit(self, X, y=None, **fit_params): Returns ------- self : Pipeline - This estimator + Pipeline with fitted steps. """ fit_params_steps = self._check_fit_params(**fit_params) Xt = self._fit(X, y, **fit_params_steps) @@ -384,7 +396,7 @@ def fit(self, X, y=None, **fit_params): return self def fit_transform(self, X, y=None, **fit_params): - """Fit the model and transform with the final estimator + """Fit the model and transform with the final estimator. Fits all the transforms one after the other and transforms the data, then uses fit_transform on transformed data with the final @@ -408,7 +420,7 @@ def fit_transform(self, X, y=None, **fit_params): Returns ------- Xt : array-like of shape (n_samples, n_transformed_features) - Transformed samples + Transformed samples. """ fit_params_steps = self._check_fit_params(**fit_params) Xt = self._fit(X, y, **fit_params_steps) @@ -425,7 +437,7 @@ def fit_transform(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict")) def predict(self, X, **predict_params): - """Apply transforms to the data, and predict with the final estimator + """Apply transforms to the data, and predict with the final estimator. Parameters ---------- @@ -446,6 +458,7 @@ def predict(self, X, **predict_params): Returns ------- y_pred : array-like + Result of calling ``predict`` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -454,7 +467,7 @@ def predict(self, X, **predict_params): @available_if(_final_estimator_has("fit_predict")) def fit_predict(self, X, y=None, **fit_params): - """Applies fit_predict of last step in pipeline after transforms. + """Apply fit_predict of last step in pipeline after transforms. Applies fit_transforms of a pipeline to the data, followed by the fit_predict method of the final estimator in the pipeline. Valid @@ -478,6 +491,7 @@ def fit_predict(self, X, y=None, **fit_params): Returns ------- y_pred : array-like + Result of calling ``fit_predict`` on the final estimator. """ fit_params_steps = self._check_fit_params(**fit_params) Xt = self._fit(X, y, **fit_params_steps) @@ -489,7 +503,7 @@ def fit_predict(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict_proba")) def predict_proba(self, X, **predict_proba_params): - """Apply transforms, and predict_proba of the final estimator + """Apply transforms, and predict_proba of the final estimator. Parameters ---------- @@ -504,6 +518,7 @@ def predict_proba(self, X, **predict_proba_params): Returns ------- y_proba : array-like of shape (n_samples, n_classes) + Result of calling ``predict_proba`` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -512,7 +527,7 @@ def predict_proba(self, X, **predict_proba_params): @available_if(_final_estimator_has("decision_function")) def decision_function(self, X): - """Apply transforms, and decision_function of the final estimator + """Apply transforms, and decision_function of the final estimator. Parameters ---------- @@ -523,6 +538,7 @@ def decision_function(self, X): Returns ------- y_score : array-like of shape (n_samples, n_classes) + Result of calling ``decision_function`` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -542,6 +558,7 @@ def score_samples(self, X): Returns ------- y_score : ndarray of shape (n_samples,) + Result of calling ``score_samples`` on the final estimator. """ Xt = X for _, _, transformer in self._iter(with_final=False): @@ -550,7 +567,7 @@ def score_samples(self, X): @available_if(_final_estimator_has("predict_log_proba")) def predict_log_proba(self, X, **predict_log_proba_params): - """Apply transforms, and predict_log_proba of the final estimator + """Apply transforms, and predict_log_proba of the final estimator. Parameters ---------- @@ -565,6 +582,7 @@ def predict_log_proba(self, X, **predict_log_proba_params): Returns ------- y_score : array-like of shape (n_samples, n_classes) + Result of calling ``predict_log_proba`` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -578,7 +596,7 @@ def _can_transform(self): @available_if(_can_transform) def transform(self, X): - """Apply transforms, and transform with the final estimator + """Apply transforms, and transform with the final estimator. This also works where final estimator is ``None``: all prior transformations are applied. @@ -592,6 +610,7 @@ def transform(self, X): Returns ------- Xt : array-like of shape (n_samples, n_transformed_features) + Transformed data. """ Xt = X for _, _, transform in self._iter(): @@ -603,7 +622,7 @@ def _can_inverse_transform(self): @available_if(_can_inverse_transform) def inverse_transform(self, Xt): - """Apply inverse transformations in reverse order + """Apply inverse transformations in reverse order. All estimators in the pipeline must support ``inverse_transform``. @@ -618,6 +637,8 @@ def inverse_transform(self, Xt): Returns ------- Xt : array-like of shape (n_samples, n_features) + Inverse transformed data, that is, data in the original feature + space. """ reverse_iter = reversed(list(self._iter())) for _, _, transform in reverse_iter: @@ -626,7 +647,7 @@ def inverse_transform(self, Xt): @available_if(_final_estimator_has("score")) def score(self, X, y=None, sample_weight=None): - """Apply transforms, and score with the final estimator + """Apply transforms, and score with the final estimator. Parameters ---------- @@ -645,6 +666,7 @@ def score(self, X, y=None, sample_weight=None): Returns ------- score : float + Result of calling ``score`` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -656,6 +678,7 @@ def score(self, X, y=None, sample_weight=None): @property def classes_(self): + """The classes labels. Only exist if the last step is a classifier.""" return self.steps[-1][1].classes_ def _more_tags(self): @@ -700,11 +723,13 @@ def get_feature_names_out(self, input_features=None): @property def n_features_in_(self): + """Number of features seen during first step `fit` method.""" # delegate to first step (which will call _check_is_fitted) return self.steps[0][1].n_features_in_ @property def feature_names_in_(self): + """Names of features seen during first step `fit` method.""" # delegate to first step (which will call _check_is_fitted) return self.steps[0][1].feature_names_in_ From 199a0f0648536bf3c2ed673c6a7de9aad5146375 Mon Sep 17 00:00:00 2001 From: Juan Martin Loyola Date: Wed, 8 Sep 2021 09:09:05 -0300 Subject: [PATCH 3/6] Update sklearn/pipeline.py Co-authored-by: Guillaume Lemaitre --- sklearn/pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 35f016e20d0e2..945f774ede25c 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -467,7 +467,7 @@ def predict(self, X, **predict_params): @available_if(_final_estimator_has("fit_predict")) def fit_predict(self, X, y=None, **fit_params): - """Apply fit_predict of last step in pipeline after transforms. + """Apply `fit_predict` of last step in pipeline after transforms. Applies fit_transforms of a pipeline to the data, followed by the fit_predict method of the final estimator in the pipeline. Valid From 8a41c6f894348d7747a59889aa08cb6abd44f54e Mon Sep 17 00:00:00 2001 From: Juan Martin Loyola Date: Wed, 8 Sep 2021 15:54:14 -0300 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Guillaume Lemaitre --- sklearn/pipeline.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 945f774ede25c..73a49258c2bb2 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -396,7 +396,7 @@ def fit(self, X, y=None, **fit_params): return self def fit_transform(self, X, y=None, **fit_params): - """Fit the model and transform with the final estimator. + """Fit the model and `transform` with the final estimator. Fits all the transforms one after the other and transforms the data, then uses fit_transform on transformed data with the final @@ -437,7 +437,7 @@ def fit_transform(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict")) def predict(self, X, **predict_params): - """Apply transforms to the data, and predict with the final estimator. + """Apply transforms to the data, and `predict` with the final estimator. Parameters ---------- @@ -567,7 +567,7 @@ def score_samples(self, X): @available_if(_final_estimator_has("predict_log_proba")) def predict_log_proba(self, X, **predict_log_proba_params): - """Apply transforms, and predict_log_proba of the final estimator. + """Apply transforms, and `predict_log_proba` of the final estimator. Parameters ---------- @@ -596,7 +596,7 @@ def _can_transform(self): @available_if(_can_transform) def transform(self, X): - """Apply transforms, and transform with the final estimator. + """Apply transforms, and `transform` with the final estimator. This also works where final estimator is ``None``: all prior transformations are applied. @@ -647,7 +647,7 @@ def inverse_transform(self, Xt): @available_if(_final_estimator_has("score")) def score(self, X, y=None, sample_weight=None): - """Apply transforms, and score with the final estimator. + """Apply transforms, and `score` with the final estimator. Parameters ---------- From 3d235022b6f430cfa9342ebcfd531363846f103a Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 9 Sep 2021 10:16:54 +0200 Subject: [PATCH 5/6] Apply suggestions from code review --- sklearn/pipeline.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 73a49258c2bb2..f14971e58ca3d 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -396,7 +396,7 @@ def fit(self, X, y=None, **fit_params): return self def fit_transform(self, X, y=None, **fit_params): - """Fit the model and `transform` with the final estimator. + """Fit the model and transform with the final estimator. Fits all the transforms one after the other and transforms the data, then uses fit_transform on transformed data with the final @@ -437,7 +437,7 @@ def fit_transform(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict")) def predict(self, X, **predict_params): - """Apply transforms to the data, and `predict` with the final estimator. + """Apply `transform`s to the data, and `predict` with the final estimator. Parameters ---------- @@ -467,7 +467,7 @@ def predict(self, X, **predict_params): @available_if(_final_estimator_has("fit_predict")) def fit_predict(self, X, y=None, **fit_params): - """Apply `fit_predict` of last step in pipeline after transforms. + """Apply `fit_predict` of last step in pipeline after `transform`s. Applies fit_transforms of a pipeline to the data, followed by the fit_predict method of the final estimator in the pipeline. Valid @@ -503,7 +503,7 @@ def fit_predict(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict_proba")) def predict_proba(self, X, **predict_proba_params): - """Apply transforms, and predict_proba of the final estimator. + """Apply `transform`s, and `predict_proba` of the final estimator. Parameters ---------- @@ -527,7 +527,7 @@ def predict_proba(self, X, **predict_proba_params): @available_if(_final_estimator_has("decision_function")) def decision_function(self, X): - """Apply transforms, and decision_function of the final estimator. + """Apply `transform`s, and `decision_function` of the final estimator. Parameters ---------- @@ -567,7 +567,7 @@ def score_samples(self, X): @available_if(_final_estimator_has("predict_log_proba")) def predict_log_proba(self, X, **predict_log_proba_params): - """Apply transforms, and `predict_log_proba` of the final estimator. + """Apply `transform`s, and `predict_log_proba` of the final estimator. Parameters ---------- @@ -596,7 +596,7 @@ def _can_transform(self): @available_if(_can_transform) def transform(self, X): - """Apply transforms, and `transform` with the final estimator. + """Apply `transform`s, and `transform` with the final estimator. This also works where final estimator is ``None``: all prior transformations are applied. @@ -647,7 +647,7 @@ def inverse_transform(self, Xt): @available_if(_final_estimator_has("score")) def score(self, X, y=None, sample_weight=None): - """Apply transforms, and `score` with the final estimator. + """Apply `transform`s, and `score` with the final estimator. Parameters ---------- From e279fcfa5d302f7a144f21ce5e732c9e92f2c4a6 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 9 Sep 2021 10:59:52 +0200 Subject: [PATCH 6/6] rework docstring --- sklearn/pipeline.py | 150 +++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 57 deletions(-) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index f14971e58ca3d..c508e55cbb636 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -54,17 +54,17 @@ class Pipeline(_BaseComposition): Sequentially apply a list of transforms and a final estimator. Intermediate steps of the pipeline must be 'transforms', that is, they - must implement fit and transform methods. - The final estimator only needs to implement fit. + must implement `fit` and `transform` methods. + The final estimator only needs to implement `fit`. The transformers in the pipeline can be cached using ``memory`` argument. The purpose of the pipeline is to assemble several steps that can be - cross-validated together while setting different parameters. - For this, it enables setting parameters of the various steps using their - names and the parameter name separated by a '__', as in the example below. - A step's estimator may be replaced entirely by setting the parameter - with its name to another estimator, or a transformer removed by setting - it to 'passthrough' or ``None``. + cross-validated together while setting different parameters. For this, it + enables setting parameters of the various steps using their names and the + parameter name separated by a `'__'`, as in the example below. A step's + estimator may be replaced entirely by setting the parameter with its name + to another estimator, or a transformer removed by setting it to + `'passthrough'` or `None`. Read more in the :ref:`User Guide `. @@ -72,10 +72,10 @@ class Pipeline(_BaseComposition): Parameters ---------- - steps : list - List of (name, transform) tuples (implementing fit/transform) that are - chained, in the order in which they are chained, with the last object - an estimator. + steps : list of tuple + List of (name, transform) tuples (implementing `fit`/`transform`) that + are chained, in the order in which they are chained, with the last + object an estimator. memory : str or object with the joblib.Memory interface, default=None Used to cache the fitted transformers of the pipeline. By default, @@ -363,8 +363,8 @@ def _fit(self, X, y=None, **fit_params_steps): def fit(self, X, y=None, **fit_params): """Fit the model. - Fit all the transforms one after the other and transform the - data, then fit the transformed data using the final estimator. + Fit all the transformers one after the other and transform the + data. Finally, fit the transformed data using the final estimator. Parameters ---------- @@ -383,7 +383,7 @@ def fit(self, X, y=None, **fit_params): Returns ------- - self : Pipeline + self : object Pipeline with fitted steps. """ fit_params_steps = self._check_fit_params(**fit_params) @@ -398,8 +398,8 @@ def fit(self, X, y=None, **fit_params): def fit_transform(self, X, y=None, **fit_params): """Fit the model and transform with the final estimator. - Fits all the transforms one after the other and transforms the - data, then uses fit_transform on transformed data with the final + Fits all the transformers one after the other and transform the + data. Then uses `fit_transform` on transformed data with the final estimator. Parameters @@ -419,7 +419,7 @@ def fit_transform(self, X, y=None, **fit_params): Returns ------- - Xt : array-like of shape (n_samples, n_transformed_features) + Xt : ndarray of shape (n_samples, n_transformed_features) Transformed samples. """ fit_params_steps = self._check_fit_params(**fit_params) @@ -437,7 +437,11 @@ def fit_transform(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict")) def predict(self, X, **predict_params): - """Apply `transform`s to the data, and `predict` with the final estimator. + """Transform the data, and apply `predict` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls `predict` + method. Only valid if the final estimator implements `predict`. Parameters ---------- @@ -457,8 +461,8 @@ def predict(self, X, **predict_params): Returns ------- - y_pred : array-like - Result of calling ``predict`` on the final estimator. + y_pred : ndarray + Result of calling `predict` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -467,11 +471,12 @@ def predict(self, X, **predict_params): @available_if(_final_estimator_has("fit_predict")) def fit_predict(self, X, y=None, **fit_params): - """Apply `fit_predict` of last step in pipeline after `transform`s. + """Transform the data, and apply `fit_predict` with the final estimator. - Applies fit_transforms of a pipeline to the data, followed by the - fit_predict method of the final estimator in the pipeline. Valid - only if the final estimator implements fit_predict. + Call `fit_transform` of each transformer in the pipeline. The + transformed data are finally passed to the final estimator that calls + `fit_predict` method. Only valid if the final estimator implements + `fit_predict`. Parameters ---------- @@ -490,8 +495,8 @@ def fit_predict(self, X, y=None, **fit_params): Returns ------- - y_pred : array-like - Result of calling ``fit_predict`` on the final estimator. + y_pred : ndarray + Result of calling `fit_predict` on the final estimator. """ fit_params_steps = self._check_fit_params(**fit_params) Xt = self._fit(X, y, **fit_params_steps) @@ -503,7 +508,12 @@ def fit_predict(self, X, y=None, **fit_params): @available_if(_final_estimator_has("predict_proba")) def predict_proba(self, X, **predict_proba_params): - """Apply `transform`s, and `predict_proba` of the final estimator. + """Transform the data, and apply `predict_proba` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `predict_proba` method. Only valid if the final estimator implements + `predict_proba`. Parameters ---------- @@ -512,13 +522,13 @@ def predict_proba(self, X, **predict_proba_params): of the pipeline. **predict_proba_params : dict of string -> object - Parameters to the ``predict_proba`` called at the end of all + Parameters to the `predict_proba` called at the end of all transformations in the pipeline. Returns ------- - y_proba : array-like of shape (n_samples, n_classes) - Result of calling ``predict_proba`` on the final estimator. + y_proba : ndarray of shape (n_samples, n_classes) + Result of calling `predict_proba` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -527,7 +537,12 @@ def predict_proba(self, X, **predict_proba_params): @available_if(_final_estimator_has("decision_function")) def decision_function(self, X): - """Apply `transform`s, and `decision_function` of the final estimator. + """Transform the data, and apply `decision_function` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `decision_function` method. Only valid if the final estimator + implements `decision_function`. Parameters ---------- @@ -537,8 +552,8 @@ def decision_function(self, X): Returns ------- - y_score : array-like of shape (n_samples, n_classes) - Result of calling ``decision_function`` on the final estimator. + y_score : ndarray of shape (n_samples, n_classes) + Result of calling `decision_function` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -547,7 +562,12 @@ def decision_function(self, X): @available_if(_final_estimator_has("score_samples")) def score_samples(self, X): - """Apply transforms, and score_samples of the final estimator. + """Transform the data, and apply `score_samples` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `score_samples` method. Only valid if the final estimator implements + `score_samples`. Parameters ---------- @@ -558,7 +578,7 @@ def score_samples(self, X): Returns ------- y_score : ndarray of shape (n_samples,) - Result of calling ``score_samples`` on the final estimator. + Result of calling `score_samples` on the final estimator. """ Xt = X for _, _, transformer in self._iter(with_final=False): @@ -567,7 +587,12 @@ def score_samples(self, X): @available_if(_final_estimator_has("predict_log_proba")) def predict_log_proba(self, X, **predict_log_proba_params): - """Apply `transform`s, and `predict_log_proba` of the final estimator. + """Transform the data, and apply `predict_log_proba` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `predict_log_proba` method. Only valid if the final estimator + implements `predict_log_proba`. Parameters ---------- @@ -581,8 +606,8 @@ def predict_log_proba(self, X, **predict_log_proba_params): Returns ------- - y_score : array-like of shape (n_samples, n_classes) - Result of calling ``predict_log_proba`` on the final estimator. + y_log_proba : ndarray of shape (n_samples, n_classes) + Result of calling `predict_log_proba` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -596,9 +621,14 @@ def _can_transform(self): @available_if(_can_transform) def transform(self, X): - """Apply `transform`s, and `transform` with the final estimator. + """Transform the data, and apply `transform` with the final estimator. - This also works where final estimator is ``None``: all prior + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `transform` method. Only valid if the final estimator + implements `transform`. + + This also works where final estimator is `None` in which case all prior transformations are applied. Parameters @@ -609,7 +639,7 @@ def transform(self, X): Returns ------- - Xt : array-like of shape (n_samples, n_transformed_features) + Xt : ndarray of shape (n_samples, n_transformed_features) Transformed data. """ Xt = X @@ -622,13 +652,13 @@ def _can_inverse_transform(self): @available_if(_can_inverse_transform) def inverse_transform(self, Xt): - """Apply inverse transformations in reverse order. + """Apply `inverse_transform` for each step in a reverse order. - All estimators in the pipeline must support ``inverse_transform``. + All estimators in the pipeline must support `inverse_transform`. Parameters ---------- - Xt : array-like of shape (n_samples, n_transformed_features) + Xt : array-like of shape (n_samples, n_transformed_features) Data samples, where ``n_samples`` is the number of samples and ``n_features`` is the number of features. Must fulfill input requirements of last step of pipeline's @@ -636,7 +666,7 @@ def inverse_transform(self, Xt): Returns ------- - Xt : array-like of shape (n_samples, n_features) + Xt : ndarray of shape (n_samples, n_features) Inverse transformed data, that is, data in the original feature space. """ @@ -647,7 +677,11 @@ def inverse_transform(self, Xt): @available_if(_final_estimator_has("score")) def score(self, X, y=None, sample_weight=None): - """Apply `transform`s, and `score` with the final estimator. + """Transform the data, and apply `score` with the final estimator. + + Call `transform` of each transformer in the pipeline. The transformed + data are finally passed to the final estimator that calls + `score` method. Only valid if the final estimator implements `score`. Parameters ---------- @@ -666,7 +700,7 @@ def score(self, X, y=None, sample_weight=None): Returns ------- score : float - Result of calling ``score`` on the final estimator. + Result of calling `score` on the final estimator. """ Xt = X for _, name, transform in self._iter(with_final=False): @@ -790,15 +824,16 @@ def _name_estimators(estimators): def make_pipeline(*steps, memory=None, verbose=False): - """Construct a Pipeline from the given estimators. + """Construct a :class:`Pipeline` from the given estimators. - This is a shorthand for the Pipeline constructor; it does not require, and - does not permit, naming the estimators. Instead, their names will be set - to the lowercase of their types automatically. + This is a shorthand for the :class:`Pipeline` constructor; it does not + require, and does not permit, naming the estimators. Instead, their names + will be set to the lowercase of their types automatically. Parameters ---------- - *steps : list of estimators. + *steps : list of Estimator objects + List of the scikit-learn estimators that are chained together. memory : str or object with the joblib.Memory interface, default=None Used to cache the fitted transformers of the pipeline. By default, @@ -814,6 +849,11 @@ def make_pipeline(*steps, memory=None, verbose=False): If True, the time elapsed while fitting each step will be printed as it is completed. + Returns + ------- + p : Pipeline + Returns a scikit-learn :class:`Pipeline` object. + See Also -------- Pipeline : Class for creating a pipeline of transforms with a final @@ -826,10 +866,6 @@ def make_pipeline(*steps, memory=None, verbose=False): >>> make_pipeline(StandardScaler(), GaussianNB(priors=None)) Pipeline(steps=[('standardscaler', StandardScaler()), ('gaussiannb', GaussianNB())]) - - Returns - ------- - p : Pipeline """ return Pipeline(_name_estimators(steps), memory=memory, verbose=verbose)