sp_randint如何工作?

Aiz*_*aac 10 python optimization machine-learning scipy scikit-learn

我正在做随机森林分类器的超参数优化.我打算使用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),
                 }
Run Code Online (Sandbox Code Playgroud)

谢谢.

Ami*_*ory 9

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])
Run Code Online (Sandbox Code Playgroud)

您可以将其更改为有意义地支持该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],
             }
Run Code Online (Sandbox Code Playgroud)

也会奏效.