Based on Sklearn Docs:
- Is it possible to force the use of
StratifiedKFold
? - How can I know which
KFold
has been used?
Based on Sklearn Docs:
StratifiedKFold
?KFold
has been used?Use this:
cross_val_score(estimator, X, y, cv=YOURCHOICE)
Example:
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)
in the sklearn documentation wrote that:
"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."...
If your model is a classifier, just use an integer for using StratifiedKFold
.
© 2022 - 2024 — McMap. All rights reserved.