Skip to content

skfolio/skfolio-sklearn-cross-val-predict

Rule skfolio-sklearn-cross-val-predict
Pack skfolio
Severity warning
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions skfolio 1.14.4 and later

scikit-learn's cross_val_predict can reject skfolio financial splitters or convert portfolio predictions to a NumPy array.

from sklearn.model_selection import cross_val_predict
result = cross_val_predict(model, returns, cv=walk)
from skfolio.model_selection import cross_val_predict
result = cross_val_predict(model, returns, cv=walk)

skfolio returns a MultiPeriodPortfolio for WalkForward and a Population for combinatorial or randomized portfolio backtests. Check downstream code when changing the return type.

Use xpd check --fix --unsafe-fixes to call cross_val_predict from skfolio.model_selection when it is imported.

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

scikit-learn cross_val_predict raises ValueError with WalkForward, CombinatorialPurgedCV and MultipleRandomizedCV in skfolio. Use skfolio.model_selection.cross_val_predict.

Browse the other rules of the skfolio pack.