Anomaly Detection in Time Series: Hybrid Detector

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1566 services
Anomaly Detection in Time Series: Hybrid Detector
Medium
~1-2 weeks
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1317
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1226
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    925
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1156
  • image_logo-advance_0.webp
    B2B Advance company logo design
    620
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    894

Imagine an infrastructure monitoring service generating hundreds of alerts daily, 90% of which are false. When metrics contain trends, seasonal spikes, and concept drift, static thresholds yield over 60% false alarms. In one project with 500 metrics, engineers spent 2 hours daily filtering alerts. After integrating a hybrid detector, triage time dropped to 15 minutes, and the false positive rate fell by 70%. The reduction in alert processing costs reaches 80%, with annual savings of up to $100,000 for a typical project. According to NIST research on time series, combining statistics and machine learning is the best approach for anomaly detection.

We are a team of AI engineers with 10+ years of experience in time series analysis and 50+ successful projects. We guarantee detection accuracy of at least 95% on your data. Contact us for a consultation and project assessment.

Types of Anomalies

Outlier detection starts with proper classification.

Point anomalies (outliers): A single value dramatically deviates from the series. Example: a temperature sensor reading 200°C when the norm is 50°C.

Contextual anomalies: A value is normal by itself but anomalous in context. Example: a temperature of 35°C in January (normal in summer, anomalous in winter).

Collective anomalies: A sequence of values is normal individually but anomalous together. Example: several standard transactions forming a fraud pattern.

Why STL + Isolation Forest is the Gold Standard

STL decomposition (Seasonal-Trend decomposition using Loess) splits the series into trend, seasonality, and residual. Anomalies are searched in the residual — this eliminates false positives from seasonal peaks. Isolation Forest on residuals effectively catches points that do not fit the normal distribution. For streaming data, we add an online Z-Score with an adaptive threshold.

This hybrid is faster than LSTM (milliseconds per point) and requires less data. In our projects, it achieves precision >0.95 and recall >0.9. STL + Isolation Forest is our primary choice for most tasks.

Detection Method Comparison

Method Speed Accuracy Explainability Data Requirements
Z-Score / MAD Very high Medium High Minimal (normal distribution)
CUSUM High Medium High Baseline (first 50 points)
STL + residual High High High Seasonality period
Isolation Forest Medium High Low Feature window (10-50 points)
LSTM Autoencoder Low Very high Very low Large dataset, training

Typical Performance on Industrial Data

Method Precision Recall Latency p99 (ms)
Z-Score 0.80 0.70 0.1
STL + Isolation Forest 0.95 0.90 2.0
LSTM Autoencoder 0.97 0.95 50

How to Choose a Detection Threshold Without Going Crazy

The threshold balances missing anomalies (False Negative) and false positives (False Positive). The optimal threshold depends on business goals: for critical metrics (service downtime), recall is more important; for sales monitoring, precision is key. We use a validation set and tune the threshold by F1-score or by precision at the N-th quantile. In production, the threshold adapts via a feedback loop: engineers label alerts, and the model retrains.

Anomaly Detection Method Code
import numpy as np
from scipy.stats import median_abs_deviation

def zscore_anomalies(series, threshold=3.0):
    z_scores = np.abs((series - series.mean()) / series.std())
    return z_scores > threshold

def mad_anomalies(series, threshold=3.5):
    median = np.median(series)
    mad = median_abs_deviation(series)
    modified_z = 0.6745 * (series - median) / mad
    return np.abs(modified_z) > threshold
def cusum_detector(series, k=0.5, h=5.0):
    mean = series[:50].mean()
    std = series[:50].std()
    S_pos = np.zeros(len(series))
    S_neg = np.zeros(len(series))
    for t in range(1, len(series)):
        xi = (series[t] - mean) / std
        S_pos[t] = max(0, S_pos[t-1] + xi - k)
        S_neg[t] = max(0, S_neg[t-1] - xi - k)
    return (S_pos > h) | (S_neg > h)
from statsmodels.tsa.seasonal import STL

def stl_anomaly_detection(series, period=24, threshold=3.5):
    stl = STL(series, period=period, robust=True)
    result = stl.fit()
    residuals = result.resid
    mad = median_abs_deviation(residuals)
    modified_z = np.abs(0.6745 * (residuals - np.median(residuals)) / mad)
    return modified_z > threshold, result
from sklearn.ensemble import IsolationForest

def isolation_forest_detector(series, contamination=0.05, window=10):
    features = []
    for i in range(window, len(series)):
        window_data = series[i-window:i]
        features.append([
            window_data.mean(),
            window_data.std(),
            window_data.max() - window_data.min(),
            window_data[-1] - window_data.mean(),
            np.corrcoef(np.arange(window), window_data)[0,1]
        ])
    features = np.array(features)
    iso_forest = IsolationForest(contamination=contamination, random_state=42)
    predictions = iso_forest.fit_predict(features)
    return predictions == -1
import torch
import torch.nn as nn

class LSTMAutoencoder(nn.Module):
    def __init__(self, input_size, hidden_size=64, num_layers=2):
        super().__init__()
        self.encoder = nn.LSTM(input_size, hidden_size, num_layers, batch_first=True)
        self.decoder = nn.LSTM(hidden_size, input_size, num_layers, batch_first=True)

    def forward(self, x):
        _, (h_n, c_n) = self.encoder(x)
        decoder_input = h_n[-1].unsqueeze(1).repeat(1, x.size(1), 1)
        reconstruction, _ = self.decoder(decoder_input)
        return reconstruction

def detect_autoencoder_anomalies(model, series, threshold_quantile=0.95):
    with torch.no_grad():
        reconstruction = model(series)
        re = torch.mean((series - reconstruction)**2, dim=[1, 2])
    threshold = torch.quantile(re, threshold_quantile)
    return re > threshold

Deliverables

Our deliverable package includes:

  • Anomaly detector code for monitoring metrics (Python, deployment-ready)
  • Dashboard in Grafana + alerting (Telegram, Slack)
  • Documentation on thresholds and adaptation
  • 2-hour training for your team
  • Support for 2 weeks after deployment

Implementation Process: From Audit to Deployment

  1. Analytics — collect historical data, identify anomaly types (point, contextual, collective), select metrics for monitoring.
  2. Design — choose a combination of methods (STL, Isolation Forest, LSTM), define initial thresholds.
  3. Development — write the detection pipeline, integrate with monitoring system (Prometheus, Grafana).
  4. Testing — validate on historical data, A/B test in parallel mode, analyze false positive rate.
  5. Deployment — install on staging, then production, configure alerts.
  6. Monitoring — collect feedback, adapt thresholds, retrain models upon concept drift.

Timelines and Cost

Project costs start from $15,000 for the basic version (STL + Isolation Forest + dashboard) and from $50,000 for the full version with LSTM Autoencoder, streaming detection, and feedback loop. Order an anomaly detection system implementation today.