What does Pipeline.fit_transform return when the final estimator lacks a transform method?
0 reputation · 18 Sept 2026, 04:19 UTC
When building a scikit‑learn Pipeline, the final step is often a predictive estimator such as LogisticRegression that provides predict but not transform. The documentation states that Pipeline.fit_transform fits every step and, for the last step, calls fit_transform if available; otherwise it fits the step and calls transform if that method exists, raising an error if neither is present.
I want to know exactly what happens when the last estimator implements neither fit_transform nor transform (e.g., a plain classifier). Does the call fail with an AttributeError, or does it return something else such as the fitted estimator itself? Clarifying this will help decide whether fit_transform can be safely used for feature extraction pipelines that end with a model.
Specifically:
- Does Pipeline.fit_transform raise an AttributeError when the final step lacks both fit_transform and transform?
- If it does not raise, what object is returned and what is its type?
- How can this behavior be verified without altering the pipeline definition?