What are the arguments for scipy.stats.uniform?

与世无争的帅哥 提交于 2020-08-06 08:00:23

问题


I'm trying to create a uniform distribution between two numbers (lower bound and upper bound) in order to feed it to sklearn's ParameterSampler. I am using scipy.stats.uniform in the following format:

from scipy.stats import uniform    
params = ParameterSampler({'bandwidth':uniform(5,50)}, 20)

But when I get the random selections of the 'bandwidth' parameter, they are not all between 5 and 50. Some of them are bigger than 50 by a bit. So my question is what do the arguments in scipy.stats.uniform represent? Are they not a lower bound and upper bound? The documentation shows no arguments so I can't figure it out from that.


回答1:


The first argument is the lower bound, and the second argument is the range of the distribution. So the example distribution in your question is uniform between 5 and 55.

Quoting from the documentation linked in your question:

A uniform continuous random variable.

This distribution is constant between loc and loc + scale.

loc is the first argument and scale is the second argument.




回答2:


In the given case the call should look like that:

uniform.rvs(loc=5, scale=45)

Even though it's possible to call the distribution directly with parameters, scipy.stats has the following logic:

<dist_name>.rvs(loc=<param1>, scale=<param2>, size=(Nx, Ny))


来源:https://stackoverflow.com/questions/44572109/what-are-the-arguments-for-scipy-stats-uniform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!