强制sklearn cross val score使用分层k折?
Forcing sklearn cross val score to use stratified k fold?
基于Sklearn Docs:
- 是否可以强制使用
StratifiedKFold
?
- 我怎么知道哪个
KFold
被使用了?
使用这个:
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)
"For int
/None
inputs, if the estimator is a classifier and y
is either binary or
multiclass, StratifiedKFold
is used. In all other cases, KFold
is
used."...
如果您的模型是分类器,只需使用整数即可 StratifiedKFold
。
基于Sklearn Docs:
- 是否可以强制使用
StratifiedKFold
? - 我怎么知道哪个
KFold
被使用了?
使用这个:
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)
"For
int
/None
inputs, if the estimator is a classifier andy
is either binary or multiclass,StratifiedKFold
is used. In all other cases,KFold
is used."...
如果您的模型是分类器,只需使用整数即可 StratifiedKFold
。