Skip to content

skfolio/skfolio-preselection-before-split

Rule skfolio-preselection-before-split
Pack skfolio
Severity warning
Fix none, edit by hand
Library versions skfolio 1.14.4 and later

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.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

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.

Browse the other rules of the skfolio pack.