Skip to content
Snippets Groups Projects
Commit 5c7f3fb9 authored by Mathieu Blondel's avatar Mathieu Blondel
Browse files

Added fit_transform() to pipeline.

parent 88a52a1b
No related branches found
No related tags found
No related merge requests found
......@@ -33,16 +33,21 @@ class Pipeline(BaseEstimator):
fit:
Fit all the transforms one after the other and transform the
data, then fit the transformed data using the final estimator
fit_transform:
Fit all the transforms one after the other and transform the
data, then use fit_transform on transformed data using the final
estimator. Valid only if the final estimator implements
fit_transform.
predict:
Applied transforms to the data, and the predict method of the
Applies transforms to the data, and the predict method of the
final estimator. Valid only if the final estimator implements
predict.
transform:
Applied transforms to the data, and the transform method of the
Applies transforms to the data, and the transform method of the
final estimator. Valid only if the final estimator implements
transform.
score:
Applied transforms to the data, and the score method of the
Applies transforms to the data, and the score method of the
final estimator. Valid only if the final estimator implements
score.
......@@ -120,7 +125,8 @@ class Pipeline(BaseEstimator):
# Estimator interface
#---------------------------------------------------------------------------
def fit(self, X, y=None, **params):
def _pre_transform(self, X, y=None, **params):
self._set_params(**params)
Xt = X
for name, transform in self.steps[:-1]:
......@@ -128,9 +134,17 @@ class Pipeline(BaseEstimator):
Xt = transform.fit_transform(Xt, y)
else:
Xt = transform.fit(Xt, y).transform(Xt)
return Xt
def fit(self, X, y=None, **params):
Xt = self._pre_transform(X, y, **params)
self.steps[-1][-1].fit(Xt, y)
return self
def fit_transform(self, X, y=None, **params):
Xt = self._pre_transform(X, y, **params)
return self.steps[-1][-1].fit_transform(Xt, y)
def predict(self, X):
Xt = X
for name, transform in self.steps[:-1]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment