gpt4 book ai didi

python - 如何告诉 RandomizedSearchCV 选择分布或 None 值?

转载 作者:行者123 更新时间:2023-12-01 03:04:12 26 4
gpt4 key购买 nike

假设我们正在尝试找到 RandomForestClassifier 的最佳 max_depth 参数。我们正在使用 RandomizedSearchCV :

from scipy.stats import randint as sp_randint
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import RandomizedSearchCV

rf_params = { # Is this somehow possible?
'max_depth': [sp_randint(1, 100), None],
}

n_iter = 10

random_search = RandomizedSearchCV(RandomForestClassifier(),
verbose=50,
param_distributions=rf_params,
n_iter=n_iter,
n_jobs=-1,
scoring='f1_micro')

random_search.fit(X_train, y_train)

是否可以告诉 RandomizedSearchCV 从指定的分布 sp_randint(1, 100) 中进行选择,或者将参数设置为 None ,这将 (如文档中所示):“...展开是节点,直到所有叶子都是纯的或直到所有叶子包含少于 min_samples_split 样本...”

当我现在运行此代码时,我会收到此错误:

enter image description here

最佳答案

同样来自docs :“如果给出一个列表,则统一采样。”使用这个:

'max_depth': list(range(1, 100)) + [None]

关于python - 如何告诉 RandomizedSearchCV 选择分布或 None 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43562952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com