Anomaly detection in timeseries with Prophet library

Anomaly detection in timeseries with Prophet libraryInsaf AshrapovBlockedUnblockFollowFollowingJun 3First of all, let’s define what is an anomaly in time series.

Anomaly detection problem for time series can be formulated as finding outlier data points relative to some standard or usual signal.

While there are plenty of anomaly types, we’ll focus only on the most important ones from a business perspective, such as unexpected spikes, drops, trend changes and level shifts.

You can solve this problem in two way: supervised and unsupervised.

While the first approach needs some labeled data, second does not, you need just raw data.

On that article, we will focus on the second approach.

Generally, unsupervised anomaly detection method works this way: you build some generalized simplified version of your data — everything which is outside some boundary by the threshold of this model is called outlier or anomaly.

So first all of we will need to fit our data into some model, which hopefully will well describe our data.

Here comes prophet library.

For sure you can try more or less powerful/complicated models such arima, regression trees, rnn/lstm or even moving averages and etc — but almost all of them need to be tuned, unlikely that will work out of the box.

Prophet is not like that, it is like auto arima but much, much better.

It is really powerful and easy to start using the library which is focused on forecasting time series.

It developed by Facebook’s Core Data Science team.

You can read more about the library here.

To install Prophet library can be installed through the pypi:pip install fbprophetWe will be working with some sample data, which has some interesting outliers.

You dowload data here and it looks something like this:Some random timeseriesTo train the model we will define basic hyperparameters interval_width and changepoint_range.

They can be used to adjust the width of the boundary:Fitting prophet modelThen we set as outliers everything which higher than the top of the and lower the bottom of the model boundary.

In addition, the set the importance of outlier as based on how far the dot from the boundary:Then you are ready get the plot.

I recomend to try altair library, you can easily get interactive plot just by setting adding .

interactive to your code.

Finally you can result we have obtained.

They seems to be very reasonable:.. More details

Leave a Reply