Open
Description
Describe the bug
Calling a pipeline with a nonparametric function causes an error since the function transform()
is missing. The pipeline itself calls the function fit_transform()
if it's present. For nonparametric functions (the most prominent being t-SNE) a regular transform()
method does not exist since there is no projection or mapping that is learned. It could still be used for dimensionality reduction.
Steps/Code to Reproduce
Example:
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from sklearn.pipeline import make_pipeline
make_pipeline(TSNE(), PCA())
Expected Results
A pipeline is created.
Actual Results
Output:
TypeError: All intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'TSNE(angle=0.5,...
Possible Solution
Editing this https://github.com/scikit-learn/scikit-learn/blob/95d4f0841/sklearn/pipeline.py#L179
to the following in order to reflect the change:
if (not hasattr(t, "fit_transform")) or not (hasattr(t, "fit") and hasattr(t, "transform")):
Versions
import sklearn; sklearn.show_versions()
System:
python: 3.8.2 (default, Feb 26 2020, 22:21:03) [GCC 9.2.1 20200130]
executable: /usr/bin/python3
machine: Linux-5.5.9-arch1-2-x86_64-with-glibc2.2.5
Python dependencies:
pip: 20.0.2
setuptools: 46.0.0
sklearn: 0.22.2.post1
numpy: 1.18.1
scipy: 1.4.1
Cython: 0.29.15
pandas: 1.0.1
matplotlib: 3.2.0
joblib: 0.14.1
Built with OpenMP: True