当验证数据已经作为一个阻碍集存在时,有什么方法可以从scikit学习中进行RandomizedSearchCV呢?我尝试将训练和验证数据连接起来,并定义cv参数,以便在两个集合合并的地方进行精确的拆分,但找不到RandomizedSearchCV接受的正确语法。
scikit-说:
cv : int, cross-validation generator or an iterable, optional
Determines the cross-validation splitting strategy.
Possible inputs for cv are:
- None, to use the default 3-fold cross validation,
- integer, to specify the number of folds in a `(Stratified)KFold`,
- An object to be used as a cross-validation generator.
- An iterable yielding train, test splits.我希望,最后一种选择应该在某种程度上起作用,但我不知道我必须以哪种格式提交它。
任何帮助都是非常感谢的!
发布于 2020-06-30 17:11:24
假设在train_indices中有训练样本的索引,在test_indices中有测试样本的索引。然后,将它们作为封装在列表中的元组传递给cv参数RandomizedSearchCV就足够了。(A)妇女权利和平等:
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV
X, y = make_classification(n_samples=10)
param_distributions = {
'n_estimators': [10, 20, 30, 40]
}
train_indices = [0, 1, 2, 3, 4]
test_indices = [5, 6, 7, 8, 9]
cv = [(train_indices, test_indices)]
search = RandomizedSearchCV(
RandomForestClassifier(),
param_distributions=param_distributions,
cv=cv,
n_iter=2
)
search.fit(X, y)这将始终在相同的样本上训练和测试估计量。如果您的数据是存储的pandas数据,例如df,请使用df.index.values获取所需的索引。
https://stackoverflow.com/questions/62656660
复制相似问题