我正在对随机森林分类器进行超参数优化。我打算使用 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/