machine-learning - sp_randint 是如何工作的?

标签 machine-learning python optimization scikit-learn scipy

我正在对随机森林分类器进行超参数优化。我打算使用 RandomSearchCV。

因此,通过检查 Scikit 中的可用代码,可以了解:sp_randint 的作用是什么? 它是否随机取一个从 1 到 11 的值?可以用其他功能代替吗?

    from scipy.stats import randint as sp_randint

    param_dist = {"n_estimators": sp_randint (1, 11), 
                  "max_depth": [3, None],
                  "max_features": sp_randint(1, 11),
                  "min_samples_split": sp_randint(1, 11),
                  "min_samples_leaf": sp_randint(1, 11),
                 }

谢谢。

最佳答案

sklearn.grid_search.RandomizedSearchCV可以获得一个param_distributions参数,将参数映射到支持rvs方法的随机分布。

在您的示例中,此对象将返回 $[1, 11)$ 范围内的随机整数:

In [8]: g = sp_randint(1, 11)

In [9]: g.rvs(20)
Out[9]: 
array([ 5,  2,  9, 10,  6,  9,  9,  8,  1,  5,  1,  8,  1,  5,  5,  4,  6,
        5,  8,  4])

您可以将其更改为有意义地支持 rvs 方法的任何其他对象,甚至是列表。例如:

param_dist = {"n_estimators": [1, 3, 4], 
              "max_depth": [3, None],
              "max_features": [1, 3, 4],
              "min_samples_split": [1, 3, 4],
              "min_samples_leaf": [1, 3, 4],
             }

同样有效。

关于machine-learning - sp_randint 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40005795/

相关文章:

r - 在glmnet中绘制ROC曲线

r - 如何在R中实现支持向量机

python-2.7 - keras自定义损失函数

python - 在Python中比较两个列表的子列表

Python - 网页抓取 - 多线程 - 线程限制?

jquery - 在切换 DOM 元素的可见性之前是否值得检查其可见性?或者这是不成熟的优化?

arrays - 径向基网络字符识别

python - 在 python 中使用 scipy 和 librosa 读取 wav 文件

Python - 使用具有多个参数的多处理不起作用

ruby - 正则表达式失败时非常慢