Skip to content

skfolio/skfolio-preselection-before-split

Pack Severity Fix Versions
skfolio warning none, edit by hand skfolio 1.14.4+

Fitting skfolio asset selection on the full input before splitting can change the assets selected using future returns.

selected = SelectKExtremes(k=1).fit_transform(returns)
result = cross_val_predict(EqualWeighted(), selected, cv=splitter)
model = make_pipeline(SelectKExtremes(k=1), EqualWeighted())
result = cross_val_predict(model, returns, cv=splitter)

The rule follows results from a direct selector construction and fit_transform into a split or skfolio cross-validation. Fit on the training set and call transform separately when splitting by hand.

Fitting skfolio preselection on all returns leaks test data. Selection chose B with all 6 rows and A with the 3 training rows. Fit the selector per training split or put it in the cross-validation pipeline.

See all rules in the skfolio pack.