是否可以强制使用分层k折?我怎么知道使用过k折?
答案 0 :(得分:1)
使用此:
cross_val_score(estimator, X, y, cv=YOURCHOICE)
示例:
from sklearn import datasets, linear_model
from sklearn.model_selection import cross_val_score
diabetes = datasets.load_diabetes()
from sklearn.model_selection import StratifiedKFold
X = diabetes.data[:150]
y = diabetes.target[:150]
lasso = linear_model.Lasso()
skf = StratifiedKFold(n_splits=2)
results = cross_val_score(lasso, X, y, cv=skf)