假设我们正在尝试找到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
哪个(如文档中所示):“... expand is节点直到所有叶子都是纯的或直到所有叶子包含少于min_samples_split的样本......“?
我现在运行此代码时会收到此错误:
答案 0 :(得分:2)
同样来自docs:"如果给出了一个列表,则统一采样。"使用此:
'max_depth': list(range(1, 100)) + [None]