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.
scipy. stats. uniform() is a Uniform continuous random variable. It is inherited from the of generic methods as an instance of the rv_continuous class. It completes the methods with details specific for this particular distribution.
uniform distribution, in statistics, distribution function in which every possible result is equally likely; that is, the probability of each occurring is the same.
The standard uniform distribution has parameters a = 0 and b = 1 resulting in f(t) = 1 within a and b and zero elsewhere. If you want to know more about fitting a set of data to a distribution, well that is in another article. It has the essential formulas that you may find useful when answering specific questions.
A uniform distribution, also called a rectangular distribution, is a probability distribution that has constant probability. This distribution is defined by two parameters, a and b: a is the minimum.
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.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With