How does sp_randint work?
<p>I am doing hyperparameter optimisation of Random Forest classifier. I am planning to use RandomSearchCV. </p>

<p>So by checking the available code in Scikit learn: What does sp_randint do?
Does it randomly take a value from 1 to 11? Can it be replaced by other function?</p>

<pre><code>    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),
                 }
</code></pre>

<p>Thank you.</p>

<p><a href="http://scikit-learn.org/0.17/modules/generated/sklearn.grid_search.RandomizedSearchCV.html" rel="nofollow"><code>sklearn.grid_search.RandomizedSearchCV</code></a> can get a <code>param_distributions</code> parameter, mapping parameters to random distributions supporting the <code>rvs</code> method.</p>

<p>In your example, this object will return random integers in the range $[1, 11)$:</p>

<pre><code>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])
</code></pre>

<p>You can change it to any other object meaningfully supporting the <code>rvs</code> method, or even a list. For example:</p>

<pre><code>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],
             }
</code></pre>

<p>will work as well.</p>

machine-learning python optimization scikit-learn scipy