Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the arguments for scipy.stats.uniform?

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.

like image 392
DataMan Avatar asked Jun 15 '17 16:06

DataMan


People also ask

What is Scipy stats uniform?

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.

What does uniform in stats mean?

uniform distribution, in statistics, distribution function in which every possible result is equally likely; that is, the probability of each occurring is the same.

What are uniform distribution parameters?

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.

How many parameters does a uniform distribution have?

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.


2 Answers

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.

like image 85
abeboparebop Avatar answered Nov 13 '22 04:11

abeboparebop


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))
like image 36
Anton K Avatar answered Nov 13 '22 04:11

Anton K