Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

stats.beta

scipy.stats.beta provides a beta continuous random variable parameterized by positive shape parameters a and b. Its distribution methods support evaluation, probability calculations, statistics, and sampling, with optional location and scale transformations.

How it works

scipy.stats.beta represents a beta continuous random variable. Provide positive shape parameters a and b; inherited distribution methods such as pdf, cdf, rvs, and interval then evaluate, summarize, or sample it, with optional loc and scale for shifting and scaling.

Syntax

scipy.stats.beta.pdf(x, a, b, loc=0, scale=1)

Parameters

NameTypeDescription
xarray_likePoint or array of points at which a distribution method is evaluated.
afloatFirst positive shape parameter.
bfloatSecond positive shape parameter.
locfloat, optionalLocation parameter used to shift the distribution.
scalefloat, optionalPositive scale parameter used to resize the distribution.

Returns

A beta continuous random-variable object with inherited distribution methods; individual methods return the corresponding density, probability, statistic, or sample result.

Key points

  • scipy.stats.beta is SciPy’s continuous beta-distribution object.
  • The distribution is parameterized by positive shape values a and b.
  • loc translates the distribution and scale changes its width.

Common mistakes

  • The default support is the standard beta interval; use loc and scale when the distribution must be translated or resized.
  • For a transformed distribution, the density is evaluated using the standardized coordinate (x - loc) / scale and divided by scale.

Example: Evaluate and sample a beta distribution

from scipy.stats import beta

alpha, beta_param = 2.0, 5.0
probability = beta.cdf(0.4, alpha, beta_param)
samples = beta.rvs(alpha, beta_param, size=4, random_state=0)

print(probability)
print(samples)

Computes a cumulative probability and draws reproducible samples from a beta distribution.

When to use it

Proportion modeling

Model a continuous quantity constrained to a proportion or probability.

Probability evaluation

Compute cumulative or tail probabilities for a beta-distributed variable.

Random sampling

Generate simulated observations for testing or Monte Carlo workflows.

Interview questions

QWhat do the parameters a and b control?

a and b are the two shape parameters of the beta distribution. They must be positive, and the standard variable is supported on the interval from 0 through 1.

Follow-up: How is a location-scale form interpreted? The standardized value is y = (x - loc) / scale, and the density is the standard beta density at y divided by scale.

QWhat operations are available on scipy.stats.beta?

The object exposes the generic continuous-distribution methods inherited from rv_continuous, including methods for density, cumulative probability, quantiles, moments, and random variates. Distribution-specific behavior supplies the beta density and its shape parameters.

Follow-up: Which method would estimate the probability of being at most x? Use beta.cdf(x, a, b), while beta.sf(x, a, b) is preferable for an upper-tail probability.

QHow does SciPy support shifted or scaled beta distributions?

The standard beta density is defined on the unit interval and depends on positive a and b. Optional loc and scale parameters transform that standard distribution without changing the underlying shape parameters.

Follow-up: How can a beta model be used on an interval other than the unit interval? Supply the target lower endpoint as loc and the interval width as scale.

  • scipy.stats.rv_continuous
  • scipy.stats.beta.pdf
  • scipy.stats.beta.cdf
  • scipy.stats.beta.rvs
  • scipy.stats.beta.fit

Source: scipy.stats.beta. Checked 2026-10-15.