[英]How does sp_randint work?
我正在做隨機森林分類器的超參數優化。 我打算使用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],
}
也會奏效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.