Skip to main content

Sktime-compatible change and anomaly detection

Project description

skchange

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

Breaking changes expected. skchange is undergoing a significant API redesign in upcoming releases. See Issue #120 and the migration guide for details.

  • New API (recommended) is previewed in skchange.new_api.* and becomes the default in 0.17.0, when the same names move to top-level (skchange.detectors, skchange.interval_scorers, skchange.penalties, ...). Drop new_api. from imports when upgrading. Still experimental.
  • Current API (skchange.change_detectors, skchange.costs, ...) emits a FutureWarning in 0.16.x and is removed in 0.17.0.

If you need stability and the old sktime compatibility, pin to a 0.15.x release:

pip install "skchange<0.16"

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

New API

from skchange.new_api.datasets import generate_piecewise_normal_data
from skchange.new_api.detectors import MovingWindow

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

detector = MovingWindow(bandwidth=20)
detector.fit(X)
detector.predict_changepoints(X)
array([ 50, 100, 150, 200])

Current API

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 segment anomaly detection

New API

from skchange.new_api.datasets import generate_piecewise_normal_data
from skchange.new_api.detectors import CAPA
from skchange.new_api.interval_scorers import L2Saving

X = 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,
)

detector = CAPA(segment_saving=L2Saving())
detector.fit(X)
detector.predict_segment_anomalies(X)
array([[100, 120],
       [250, 300]])

Current API

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()
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skchange-0.16.0.tar.gz (2.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skchange-0.16.0-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file skchange-0.16.0.tar.gz.

File metadata

  • Download URL: skchange-0.16.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for skchange-0.16.0.tar.gz
Algorithm Hash digest
SHA256 2c54033c4b576ab4a81113326b87ae33216f625bfa327b041337ea623b85ec81
MD5 cfd86e87e9ff28eb42183e3d2662b885
BLAKE2b-256 24c6140d01c13fb2d2dd02414e4a88aebb20c5647520bffb8ce219bbacdac3cc

See more details on using hashes here.

File details

Details for the file skchange-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: skchange-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for skchange-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93a4652000013a0872b23fb1de381332031765e158c78f399b1f040f7e0270ef
MD5 b93c6bb1d0bbf19d0075fda29cff265c
BLAKE2b-256 a8866b0e2553b1da71ed795f3c9fa1e3c216c97d95dd8c9d67be74861bc5bbfe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page