Open In App

Uniform Distribution in Data Science

Last Updated : 06 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Uniform Distribution also known as the Rectangular Distribution is a type of Continuous Probability Distribution where all outcomes in a given interval are equally likely. Unlike Normal Distribution which have varying probabilities across their range, Uniform Distribution has a constant probability density throughout the interval which results in a "flat" distribution.

Key Concepts of the Uniform Distribution

1. Events and Interval

Uniform Distribution applies to events that are equally likely within a fixed interval [a,b]. This interval can represent time, space or any continuous measurement. The events within this interval are random and independent but they all have the same likelihood of occurring.

Example: If a fair die is rolled each side (1 to 6) is equally likely to appear which represents a discrete uniform distribution. In contrast, a continuous uniform distribution could model the outcome of a randomly chosen time within a 24-hour day where every moment has the same probability.

2. Probability Density Function (PDF)

PDF for a Uniform Distribution is a constant value across the entire interval [a,b]. This is because every point in the interval is equally likely to be chosen. Formula for the Uniform PDF is:

f(x) = \frac{1}{b - a}, \quad a \leq x \leq b

For any x outside the interval [a,b] the PDF is zero:

f(x) = 0, \quad \text{for} \ x < a \ \text{or} \ x > b

Example: For a uniform distribution on the interval [0,25] the PDF is:

f(x) = \frac{1}{25 - 0} = 0.04, \quad 0 \leq x \leq 25

This means every value between 0 and 25 has the same probability of occurring.

3. Cumulative Distribution Function (CDF)

CDF provides the probability that the random variable is less than or equal to a specific value x. For a Uniform Distribution, the CDF is calculated as the cumulative sum of the PDF over the range from a to x and its formula is:

F(x) = \begin{cases} 0, & \text{if} \ x < a \\\frac{x - a}{b - a}, & \text{if} \ a \leq x \leq b \\1, & \text{if} \ x > b\end{cases}

Example: For a Uniform Distribution between a = 0 and b = 25 the CDF is:

F(x) = \begin{cases} 0, & \text{if} \ x < 0 \\\frac{x}{25}, & \text{if} \ 0 \leq x \leq 25 \\1, & \text{if} \ x > 25\end{cases}

This shows that for any value of x, the probability that X ≤ x is simply the proportion of the interval up to x.

Properties of the Uniform Distribution

1. Expected Value (Mean)

The expected value of a Uniform Distribution represents the central tendency of the distribution. It is the average of the lower and upper bounds of the interval which is calculated as:

E[X] = \frac{a + b}{2}

Example: For a Uniform Distribution with a=0 and b=25, the expected value is:

E[X] = \frac{0 + 25}{2} = 12.5

This means the average value of the random variable X is 12.5.

2. Variance

The variance of the Uniform Distribution measures the spread of values around the mean and its formula is:

Var(X) = \frac{(b - a)^2}{12}

Example: For a=0 and b=25, the variance is:

Var(X) = \frac{(25 - 0)^2}{12} = \frac{625}{12} \approx 52.08

This tells us how much the values are expected to deviate from the mean.

3. Standard Deviation

The standard deviation is the square root of the variance and provides a measure of the dispersion of the distribution. The formula for the standard deviation is:

\sigma = \sqrt{Var(X)} = \frac{b - a}{\sqrt{12}}

Example: For a=0 and b=25:

\sigma = \frac{25 - 0}{\sqrt{12}} \approx 7.21

Example: Uniform Distribution in Copper Wire

Let’s apply the Uniform Distribution to a real-world scenario. Suppose the current measured in a piece of copper wire is uniformly distributed over the interval [0,25]. We can calculate the PDF, mean, variance, standard deviation and CDF.

1. PDF: f(x) = \frac{1}{25 - 0} = 0.04, \quad 0 \leq x \leq 25

2. Expected Value: E[X] = \frac{0 + 25}{2} = 12.5

3. Variance: Var(X) = \frac{(25 - 0)^2}{12} = \frac{625}{12} \approx 52.08

4. Standard Deviation: \sigma = \frac{25 - 0}{\sqrt{12}} \approx 7.21

5. CDF: F(x) =\begin{cases} 0, & \text{if} \ x < 0 \\\frac{x}{25}, & \text{if} \ 0 \leq x \leq 25 \\1, & \text{if} \ x > 25\end{cases}

Python Implementation for Uniform Distribution

Here we implement the Uniform Distribution in Python and we will be using NumPy and Matplotlib libraries to and visualize random samples from a uniform distribution.

Python
import numpy as np
import matplotlib.pyplot as plt
a = 0  
b = 25  
samples = np.random.uniform(a, b, 1000)

plt.hist(samples, bins=30, density=True, alpha=0.6, color='g')

x = np.linspace(a, b, 1000)
plt.plot(x, np.ones_like(x) / (b - a), 'r-', lw=2)

plt.title('Uniform Distribution PDF')
plt.xlabel('X')
plt.ylabel('Probability Density')
plt.show()

Output:

ud1
Result

Applications of the Uniform Distribution

Uniform Distribution is used in various real-world scenarios where all outcomes within a specific interval are equally likely, some common applications include:

  1. Random Sampling: In simulations, random numbers are drawn from a Uniform Distribution to simulate random behavior.
  2. Quality Control: In manufacturing, they models variations in product measurements when there’s no systematic bias.
  3. Lottery and Gaming: The distribution is used to model random number selection in lottery games or shuffling cards.
  4. Random Time Intervals: If an event is equally likely to occur at any moment within a given time frame this can model the time of occurrence.

Mastering the Uniform Distribution helps us with a tool for modeling scenarios where each outcome within a specified range is equally likely and it provides a solid foundation for applications in random sampling, quality control and simulations.


Next Article

Similar Reads