如何告诉 RandomizedSearchCV 选择分布或 None 值?
How to tell RandomizedSearchCV to choose from distribution or None value?
假设我们正在尝试找到 RandomForestClassifier
. We are using RandomizedSearchCV
的最佳 max_depth
参数:
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 个样本..."?
当我现在运行这段代码时,我会得到这个错误:
也来自 docs:"If a list is given, it is sampled uniformly." 使用这个:
'max_depth': list(range(1, 100)) + [None]
假设我们正在尝试找到 RandomForestClassifier
. We are using RandomizedSearchCV
的最佳 max_depth
参数:
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 个样本..."?
当我现在运行这段代码时,我会得到这个错误:
也来自 docs:"If a list is given, it is sampled uniformly." 使用这个:
'max_depth': list(range(1, 100)) + [None]