SciPy stats.beta Function

Lakshay Kapoor Jan 30, 2023
  1. the scipy.stats.beta() Function
  2. Beta Continuous Random Variable
  3. Beta Random Variates and Probability Distribution Function
SciPy stats.beta Function

Beta distribution in statistics is defined as a group of consecutive probability distributions defined between the interval [0,1]. The beta distribution has two parameters known as shape parameters. These shape parameters are denoted by α and β that control the shape of the whole distribution and represent a random variable’s exponents.

the scipy.stats.beta() Function

The scipy.stats.beta() function of the SciPy library is a beta continuous random variable defined with various shape parameters and a standard format to complete the function’s specifications properly.

Following are the parameters of the scipy.stats.beta function.

q It defines the upper and lower end tail of the probability.
a, b It defines the shape parameters of the function.
x It defines the quantiles.
loc It defines the location parameter of the function. The default value of this function is 0.
scale The default value of the scale parameter is 1.
size It is defined in the form of a tuple of integers. It defines the shape of random variates.
moments It is defined by letter i.e, msvk, where m = mean, v = variance, s = Fisher's skew, and k = Fisher's kurtosis.

All the parameters except q, a,b, and x are optional. That means it is unnecessary to define them every time while using the scipy.stats.beta function.

There are various methods to define the scipy.stats.beta function:

  • rvs(a, b, loc=0, scale=1, size=1, random_state=None)- This method is used whenever there is a need to find random variates.
  • pdf(x, a, b, loc=0, scale=1)- This method is known as the probability density function
  • cdf(x, a, b, loc=0, scale=1)- This method is known as the cummulative distribution function
  • logcdf(x, a, b, loc=0, scale=1)- This method finds the log of the cummulative distribution function.

There are many more such methods to define the scipy.stats.beta function. But in every method, the value of the parameters varies.

Beta Continuous Random Variable

from scipy.stats import beta

num_args = beta.numargs
[a, b] = [
    1.2,
] * num_args
random_var = beta(a, b)

print("Random Variable : ", random_var)

Output:

Random Variable :  <scipy.stats._distn_infrastructure.rv_frozen object at 0x7f9a6b366af0>

Beta Random Variates and Probability Distribution Function

In this example, the arange function of the NumPy library is used. This is a built-in function of the NumPy library that helps return an array object with a specific number of values with a definite spacing.

import numpy as np

quantile_val = np.arange(0.1, 1, 0.2)

rv = beta.rvs(a, b, scale=2, size=10)
print("Random Variates : ", rv)

rv_pdf = beta.pdf(quantile_val, a, b, loc=0, scale=1)
print("Probability Distribution : ", rv_pdf)

Output:

Random Variates :  [0.33734047 1.72002734 1.67064615 0.72633407 0.71346865 0.81301286
 1.39419329 0.65489343 0.97953887 1.15867132]
Probability Distribution :  [0.91029949 1.07839945 1.11666731 1.07839945 0.91029949]
Lakshay Kapoor avatar Lakshay Kapoor avatar

Lakshay Kapoor is a final year B.Tech Computer Science student at Amity University Noida. He is familiar with programming languages and their real-world applications (Python/R/C++). Deeply interested in the area of Data Sciences and Machine Learning.

LinkedIn

Related Article - SciPy Stats