问题
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
andloc + 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