如何告诉RandomizedSearchCV选择分配还是无值?

时间:2017-04-22 18:22:13

标签: python scipy scikit-learn random-forest hyperparameters

假设我们正在尝试找到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的样本......“

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

  

enter image description here

1 个答案:

答案 0 :(得分:2)

同样来自docs:"如果给出了一个列表,则统一采样。"使用此:

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