Exponential Distribution

The exponential distribution is used to model the time between events in a process that occurs at a constant average rate, such as time between arrivals of buses or emails.

Key Topics

Generating Exponential Distribution

NumPy's random.exponential() function generates random numbers based on the exponential distribution. You can specify the scale parameter, which is the inverse of the rate (lambda).

Example

# Generating exponential distribution
import numpy as np

# Average time between events = 2 seconds
times = np.random.exponential(scale=2, size=10)

print("Inter-arrival times:", times)

Output

Inter-arrival times: [1.2 0.5 3.1 2.3 0.8 ...]

Explanation: The random.exponential() function generates random times between events, where the average time between events is specified by the scale parameter.

Visualizing the Distribution

You can visualize the exponential distribution using a histogram to observe the decreasing probability as time increases.

Example

# Visualizing exponential distribution
import seaborn as sns
import matplotlib.pyplot as plt

# Data
times = np.random.exponential(scale=2, size=1000)

# Plot
sns.histplot(times, kde=True, color="red")
plt.title("Exponential Distribution of Inter-Arrival Times")
plt.xlabel("Time Between Events")
plt.ylabel("Frequency")
plt.show()

Output

A histogram with a decreasing curve showing inter-arrival times.

Explanation: The histogram shows the exponential decay in the probability of events occurring as time increases.

Key Takeaways

  • Exponential Distribution: Models the time between events occurring at a constant average rate.
  • Simulation: Use random.exponential() for scenarios like customer arrivals or system failures.
  • Visualization: Histograms illustrate the rapid decay in event probabilities over time.
  • Applications: Analyze service times, wait times, or event inter-arrivals.