Exponential Distribution
The Exponential Distribution is a continuous distribution that models the time between events in a Poisson process, such as the time between website visits or customer loyalty. It is defined by a single parameter, lambda (λ), which represents the rate at which events occur. The Exponential Distribution is memoryless, meaning that the time between events does not depend on the time since the last event.
In the following example we will cover how exponential distribution is being used by an online e-commerce company and answer the following questions:
How often do we get orders?
Does the dataset actually follow an Exponential Distribution?
Is the lambda value we chose really the best value to define the distribution?
You can access to the dataset here. The full Jupyter notebook is accessible via https://github.com/sedarsahin/Distributions/blob/main/Exponential/interval_between_orders.ipynb
1. How often do we get orders?
The number of visits between orders for an e-commerce website in a certain time period in January 2024 is stored in the array order_visits.
If we assume that website visits resulting in orders can be modeled using a Poisson distribution, then the time between these visits (also known as the interval time) follows an Exponential distribution.
The Poisson distribution is a suitable model for counting the number of events (orders) occurring in a fixed interval (e.g., website visits) if the following conditions are met:
Events are independent: Each website visit is an independent event, and the occurrence of an order does not affect the probability of another order.
Events occur at a constant rate: The rate at which orders occur is constant over the fixed interval (website visits).
Events are rare: The probability of an order occurring in a single website visit is relatively low (less than 10-15%)
The Exponential distribution is a continuous distribution that describes the time between events, i.e. the interval time, in a Poisson process. It has a single parameter, λ(lambda), a.k.a rate parameter, which represents the rate at which events occur.
The Exponential distribution has several important properties, including:
Memorylessness: the time between events does not depend on the time since the last event
Constant rate: the rate at which events occur is constant over time
Exponential decay: the probability of waiting for a certain amount of time before the next event decays exponentially
λ is simply the average number of visits between orders and will be calculated directly from the dataset (order_visits). The mean of visits between orders will make the exponential distribution best fit to the data.
Note the shape of the distribution of the samples, it is maximum at 0 and decays as we go far from the origin, characteristic to the Exponential distribution.
2. Does the dataset actually follow an Exponential Distribution?
To answer this question we will create an empirical cumulative distribution function (eCDF) of the real data and compare it with the theoretical CDF (tCDF). If the two overlaps, we can that conclude that the Exponential distribution describes the observed data.
In order to draw such conclusion we will follow the following steps:
Create a eCDF function, and use it to compute CDF from the actual dataset (order_visits).
We will use the same function to compute tCDF from the theoretical samples (interval_time_btw_orders).
Plot x_theor and y_theor Then overlay the ECDF of the real data x and y as points.
The empirical CDF is usually defined as
CDF(x) = (Number of Samples <= x) / Number of Samples
It looks like visits result in orders (order_visits) are indeed Exponentially distributed since the dataset closely follows the theoretical cumulative distribution.
3. Is the lambda value we chose really the best value to define the distribution?
Let's test this we two different values for lambda:
3 times the lambda
1/3 of the lambda
We will draw new samples using these values and ingest them to our eCDF function. Then plot them along with actual and theoretical sample obtained via lambda.
Note that only the mean value of order_visits, i.e. lambda, fits the data almost perfectly. Therefore we can conclude that the mean of order_visits, is the best value for the rate parameter, lambda.
Last updated