Prince foo

Frequently Asked Questions

How to use Prince with sklearn pipelines?

Most Prince estimators consume and produce pandas DataFrames. PCA also accepts NumPy arrays, and all estimators with two-dimensional tabular input accept Polars DataFrames through Narwhals; see DataFrame support. In a sklearn pipeline, use sklearn’s set_output API to choose the DataFrame type exchanged between compatible 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