2017-04-22 41 views
1

比方说,我们正试图找到RandomForestClassifier的最佳参数max_depth。我们使用RandomizedSearchCV如何判断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

回答

1
docs

又道:“如果给出一个列表,它是均匀采样”使用这个:

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

谢谢你的回答,但现在真的有很小的机会从这样的列表中随机选择'None',这可以以某种方式改进吗? – delusionX

+0

什么是“改进”给你?我问,因为如果你想保证它被选中,你最好用GridSearchCV。 –

+0

也许一些不同的分布比统一,让我们说几何(https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.geom.html#scipy.stats.geom)哪里没有高概率P(x =无)。 – delusionX

相关问题