Skip to content

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.

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_piecewise_normal_data

df = generate_piecewise_normal_data(
    means=[0, 5, 10, 5, 0],
    lengths=[50, 50, 50, 50, 50],
    seed=1,
)

detector = MovingWindow(bandwidth=20)
detector.fit_predict(df)
   ilocs
0     50
1    100
2    150
3    200

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_piecewise_normal_data
from skchange.penalties import make_linear_chi2_penalty

df = generate_piecewise_normal_data(
    means=[0, 8, 0, 5],
    lengths=[100, 20, 130, 50],
    proportion_affected=[1.0, 0.1, 1.0, 0.5],
    n_variables=10,
    seed=1,
)

score = L2Saving()  # Looks for segments with non-zero means.
penalty = make_linear_chi2_penalty(score.get_model_size(1), df.shape[0], df.shape[1])
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, 0, 3, 1, 4]

License

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •