Prince foo

Frequently Asked Questions

How to use Prince with sklearn pipelines?

Prince estimators consume and produce pandas DataFrames. If you want to use them in a sklearn pipeline, you can sklearn’s set_output API. This way, you can tell sklearn that the pipeline should exchange DataFrames instead of numpy arrays between the steps.

from __future__ import annotations

from sklearn import datasets, impute, pipeline

import prince

pipe = pipeline.make_pipeline(impute.SimpleImputer(), prince.PCA())
pipe.set_output(transform="pandas")
dataset = datasets.load_iris()
pipe.fit_transform(dataset.data).head()
01
0-2.2647030.480027
1-2.080961-0.674134
2-2.364229-0.341908
3-2.299384-0.597395
4-2.3898420.646835