linusdm

linusdm

Any tips or references for detecting anomalies in timeseries data?

This is a question from someone who is mostly ignorant of the possibilities of ML and AI in general, keep that in mind :wink:

I’m working on a project where timeseries data is ingested from various sensors (think: temperature, pressure, etc.). One of the core responsibilities of the product is to define specifications for these streams of values, and trigger notifications when things go out of specification. In other words, it’s all about alarms. But the specifications can be somewhat more complex than defining threshold values, as there are strategies to consider a window where n out of N values cannot exceed some threshold for example. Other, rather straightforward rules can also be specified.

Now, I was wondering whether there are ML related strategies that can perform the detection of anomalies in such timeseries data? Maybe even without defining the thresholds (or in addition to a comparison to some thresholds). For example, it would be nice to detect drifting values (which is harder to detect because of slowness of change). Or when there are patterns of temperature change (sometimes the temperature does not stay constant, but it varies according to some pattern during some kind of production process), it would be nice to detect deviations from the patterns that usually occur.

I hope my question is clear. I have high hopes for machine learning and AI in this domain, but I have zero knowledge or intuition of how to tackle or explore the possibilities.

TLDR: any tips or references for detecting anomalies in timeseries data? Is ML even a good fit for such an analysis?

Thanks!

Most Liked

lucaong

lucaong

As others noted, anomaly detection in time series is a huge topic.

Some specific cases are trivial, such as simple thresholds or triggers based on deviation from a norm. Ultimately though, on non-trivial dynamic processes, the definition of an anomaly is very context-dependent.

There are very different algorithms out there, but the basic idea (with wildly different implementations) is that an algorithm would try to predict the next value(s) on the basis of the past, observe the actual value, and measure how far off the prediction was: if it’s very different, it is considered an anomaly. The problem is to choose a prediction model that is sophisticated enough to take into account all known effects: seasonality, patterns, range of frequencies where random oscillations are expected, self-correlation, measurable inputs that affect your system, etc.

The more known effects you add to your prediction, the more your solution will become a custom dynamic model, departing from off-the-shelf algorithms.

It is possible to use ML to learn patterns vs anomalies, but often not easy, due to the fact that anomalies are by definition rare, and do not necessarily look the same. Without proper care to avoid overfitting, if anomalies are rare enough, an ML algorithm could achieve seemingly good results by just labeling everything as “not anomaly”, which is obviously useless. You will therefore need to assess how expensive a false positive is for your case, vs. a false negative.

I know this is not a specific suggestion for an algorithm, and might not be too helpful, but I’d recommend to:

  • Reason on what you know about the dynamics of your system. Seasonality, frequency range, measurable inputs that can affect your system and might feed into the model.
  • Assess the cost of false positives vs. false negatives. If false positives are cheap, you can make your algorithm more sensitive, in the attempt to catch all anomalies. Otherwise things get harder. In any case, you’ll need to decide on this important trade off.
  • How fast should your alerting system react? If it needs to be very fast, it won’t be able to wait and weight in more observations to see if a seemingly strange pattern normalizes (or, equivalently, use longer windows for weighted averages). This makes your alerting more susceptible to noise, and might put limits on the false positive rate.
  • Start simple, evaluate, and add up: how many anomalies do you catch with a simple threshold model, maybe normalizing seasonalities? What kind of anomalies are missed? If you add thresholds also on the first derivative (growth, as opposed to absolute value), would such anomalies be detected?

In sum, know your system, and split the big problem into separate ones that can each be solved by a known algorithm.

I believe that ML in this case is not a silver bullet, and comes after a proper problem definition. It’s ok to introduce ML if necessary, but deep knowledge of the system, if possible at all, will likely beat ML in this case. Even if you do use ML, you will need to pick an algorithm, prepare its input, and tweak its parameters based on such knowledge of your system.

antoine-duchenet

antoine-duchenet

Hi !

This is a vast question!

Yes, ML could be a good fit, however the NFL theorem would tell you that there are no easy shortcuts to success and every tips we could give you will have to be put to the test with your own data!

I mostly work on Natural Language Processing problems thus time series are not really my domain of expertise but I can try to give you some clues:

There are a lot of ML tools able to be used for anomaly / outliers / novelty detection such as SVM, Isolation Forest, LOF, Auto Encoders, Spectral Residual, Seq2Seq… and drift detection may require other solutions.

The only (quite simple) TS problem I’ve been confronted has been solved by a Spectral Residual approach for the outlier detection part and by a Context Aware Maximum Mean Discrepancy (CAMMD) approach for the drift detection part thus if I had to solve another similar problem I would probably give those ones a shot.

As a general advice, even if you do not implement your solution with the Python language, the documentation of scikit-learn may give you some basic understanding of some possible approaches:

The documentation of alibi-detect could give you some keywords to look for too: GitHub - SeldonIO/alibi-detect: Algorithms for outlier, adversarial and drift detection · GitHub .

I hope this helps!

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement