NumPy - Pareto Distribution



What is Pareto Distribution?

The Pareto Distribution is a continuous probability distribution used to model the distribution of wealth, income, or other resources, where a small portion of the population controls a large proportion of the total.

It is defined by two parameters: the shape parameter and the scale parameter xm. The distribution is known for its "80/20 rule," where roughly 80% of the effects come from 20% of the causes.

Example: The Pareto distribution can model the distribution of wealth in a population, where a few individuals hold most of the wealth.

The probability density function (PDF) of the Pareto distribution is −

f(x; , xm) = ( * xm) / x+1, for x  xm

Where,

  • : Shape parameter, which determines the steepness of the distribution's tail.
  • xm: Scale parameter, which represents the minimum value of the distribution (also known as the "threshold").
  • x: Random variable representing the value we are interested in.
  • + 1: The exponent of the random variable, showing the heavy-tailed nature of the distribution.

The Pareto distribution is commonly used in the modeling of "rich-get-richer" phenomena, where the probability of a value decreases rapidly as the value increases.

Pareto Distributions in NumPy

NumPy provides a built-in function numpy.random.pareto() function to generate random samples from the Pareto distribution. You need to specify the shape parameter and scale parameter xm. The function will generate random values according to the Pareto distribution.

Example

In this example, we generate 10 random samples from the Pareto distribution with a shape parameter () of 2 and a scale parameter (xm) of 1. Since the Pareto distribution is defined for values greater than or equal to xm, we add 1 to shift the distribution to start at 1 −

import numpy as np

# Generate 10 random samples from a Pareto distribution with shape parameter =2 and scale parameter xm=1
samples = np.random.pareto(a=2, size=10) + 1  # xm=1, we add 1 to shift the distribution
print("Random samples from Pareto distribution:", samples)

Following is the output obtained −

Random samples from Pareto distribution: [11.21752644  1.19133192  1.13107575  1.00672706  1.77411845  1.29541783
  5.99272696  1.62119397  1.08409404  1.25025651]

Visualizing Pareto Distributions

Visualization is an important tool to understand the characteristics of distributions. We can visualize the Pareto distribution by creating histograms using Matplotlib.

Example

In the following example, we are first generating 1000 random samples from a Pareto distribution. We are then creating a histogram of the samples to visualize this distribution −

import numpy as np
import matplotlib.pyplot as plt

# Generate 1000 random samples from a Pareto distribution
samples = np.random.pareto(a=2, size=1000) + 1

# Plot the histogram of the samples
plt.hist(samples, bins=30, density=True, edgecolor='black')
plt.title('Pareto Distribution')
plt.xlabel('Value')
plt.ylabel('Probability Density')
plt.grid(True)
plt.show()

The histogram shows the probability density of the generated values. As expected, the distribution has a "heavy tail," meaning that a small number of larger values contribute significantly to the total probability. The distribution decays quickly as the values increase −

Pareto Distribution

Parameters of the Pareto Distribution

The two parameters of the Pareto distribution, and xm, plays an important role in shaping the distribution. Let us break down how each parameter affects the distribution −

  • Shape Parameter (): The shape parameter controls the steepness of the distribution's tail. As increases, the tail becomes steeper, and the distribution becomes less "heavy-tailed." A smaller results in a distribution with a heavier tail and more extreme values.
  • Scale Parameter (xm): The scale parameter sets the minimum value for the distribution. A higher xm shifts the distribution to the right, meaning that the random samples will only take values greater than or equal to this threshold.

Applications of Pareto Distribution

The Pareto distribution has many practical applications in modeling and data analysis −

  • Economics: The Pareto distribution is often used to model income distribution, wealth distribution, and other economic phenomena where a small portion of the population controls a large proportion of the wealth.
  • Network Traffic: It can be used to model internet traffic, where a small number of users generate the majority of the data.
  • Insurance: The Pareto distribution is applied in risk modeling, particularly in areas like natural disasters, where large losses are rare but significant.
  • Engineering: It is used to model component failures in engineering, where a few components fail frequently while the rest have long lifespans.

Statistical Properties of the Pareto Distribution

Like other distributions, the Pareto distribution has some interesting statistical properties −

  • Mean: The mean of the Pareto distribution is * xm / ( - 1) for > 1. If 1, the mean is undefined because the distribution has a heavy tail.
  • Variance: The variance of the Pareto distribution is * xm / (( - 1) * ( - 2)) for > 2. If 2, the variance is infinite due to the heavy tail.
  • Skewness: The Pareto distribution is skewed to the right, meaning it has a long tail on the positive side.

Generating a Pareto Distribution with Custom Parameters

You can modify the shape and scale parameters to generate Pareto distributions that better reflect your data.

Example

Following is an example where we set =3 and xm=2 to generate a pareto distribution −

import numpy as np
import matplotlib.pyplot as plt

# Generate 1000 random samples with =3 and xm=2
samples = np.random.pareto(a=3, size=1000) + 2

# Plot the histogram of the samples
plt.hist(samples, bins=30, density=True, edgecolor='black')
plt.title('Pareto Distribution with =3 and xm=2')
plt.xlabel('Value')
plt.ylabel('Probability Density')
plt.grid(True)
plt.show()

This graph will show a distribution with a slightly less heavy tail than the one with =2 and xm=1 −

Customized Pareto Distribution

Seeding for Reproducibility

For reproducibility, it is important to set a random seed. This ensures that every time you run the code, you get the same set of random numbers.

Example

By setting the seed, you ensure that the random generation produces the same result every time the code is executed as shown in the example below −

import numpy as np

# Set the seed for reproducibility
np.random.seed(42)

# Generate 10 random samples with =2 and xm=1
samples = np.random.pareto(a=2, size=10) + 1
print("Random samples from Pareto distribution with seed:", samples)

The result produced is as follows −

Random samples from Pareto distribution with seed: [1.26444595 4.50442711 1.93164669 1.57849408 1.08851288 1.08849733
 1.03037147 2.73358909 1.58334718 1.85081305]
Advertisements