Parametric event detection in python with evDetect
- Nick Gavriil
- Nov 2, 2024
- 2 min read
Introducing evDetect, the python library for event detection and inference
Introduction
As a data scientist I have come numerous times across problems that require detection and measurement of the effect of events so I created a minimal python open-source library to automate the process.
Event detection is relevant when you are looking to analyse time series data and catch:
Spikes from marketing / PR events
Sales spikes from holidays and one-off discount events
Spikes in infrastructure metrics
Changes in baselines of different product KPIs
How it works
Event detection comes in handy when there is a plethora of time series KPIs you would like to scan for spikes or changes in baselines without having to go manually through each one of them. For example, in the context of a mobile app you would be looking for acquisition spikes from PR events across multiple cities or countries. Furthermore, by using parametric statistical models we can describe each event with a couple of parameters and compare or document events based on their magnitude and duration.
evDetect scans through a time series looking for such events by assuming that the impact of an event can be approximated by an exponential decay process:

which looks something like this:

In addition, we can also approximate changes in baselines with an exponential decay process by representing it as a decay with infinite half-life or equivalently with lambda=0.
evDetect scans through the series and as well as various values for the lambda parameter in order to identify the process that best approximates an event if it exists. Let’s see how this would look like.
Below we have some synthetic data for an event of finite half-life.

For the above series, evDetect returns the following summary:
{
'detected': True,
'event_time': 200,
'event_halflife': 4.6,
'decay_lambda': 0.15,
'amplitude': 5.76,
'trend': 0.0,
'rsquared': 0.81
}
In the case of a change in baseline for a metric we can also use evDetect. For the next example, we will also add a trend in our series.

and the summary of the results:
{
'detected': True,
'event_time': 200,
'event_halflife': inf,
'decay_lambda': 0.0,
'amplitude': 4.97,
'trend': 0.01,
'rsquared': 1.0
}
Try it out
If you would like to try it, you can find the project’s Github page here and you can install it simply through pip
pip install evdetect
Comments