Skip to content

skchange provides sktime-compatible change detection and changepoint-based anomaly detection algorithms

License

Notifications You must be signed in to change notification settings

NorskRegnesentral/skchange

Repository files navigation

skchange

codecov tests docs BSD 3-clause !black Python PyPI - Downloads

skchange provides sktime-compatible change detection and changepoint-based anomaly detection algorithms.

Experimental but maturing.

Check out the latest version: v0.12.0

Documentation

Installation

It is recommended to install skchange with numba for faster performance:

pip install skchange[numba]

Alternatively, you can install skchange without numba:

pip install skchange

Quickstart

Changepoint detection / time series segmentation

from skchange.change_detectors import MovingWindow
from skchange.datasets import generate_alternating_data

df = generate_alternating_data(n_segments=10, segment_length=50, mean=5, random_state=1)

detector = MovingWindow(bandwidth=20)
detector.fit_predict(df)
   ilocs
0     50
1    100
2    150
3    200
4    250
5    300
6    350
7    400
8    450

Multivariate anomaly detection with variable identification

from skchange.anomaly_detectors import CAPA
from skchange.anomaly_scores import L2Saving
from skchange.compose.penalised_score import PenalisedScore
from skchange.datasets import generate_anomalous_data
from skchange.penalties import make_linear_chi2_penalty

n = 300
anomalies = [(100, 120), (250, 300)]
means = [[8.0, 0.0, 0.0], [2.0, 3.0, 5.0]]
df = generate_anomalous_data(n, anomalies, means, random_state=3)
p = df.shape[1]

score = L2Saving()
penalty = make_linear_chi2_penalty(score.get_model_size(1), n, p)
penalised_score = PenalisedScore(score, penalty)
detector = CAPA(penalised_score, find_affected_components=True)
detector.fit_predict(df)
        ilocs  labels   icolumns
0  [100, 120)       1        [0]
1  [250, 300)       2  [2, 1, 0]

License

skchange is a free and open-source software licensed under the BSD 3-clause license.