Skchange
A python library for fast changepoint and segment anomaly detection
Install / Use
npx skills add NorskRegnesentral/skchangeInstalls into whichever agent you are using.
README
skchange
<!-- [skchange]((https://skchange.readthedocs.io/en/latest/)) provides [scikit-learn](https://scikit-learn.org/)-like changepoint detection algorithms. -->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, ...). Dropnew_api.from imports when upgrading. Still experimental. - Current API (
skchange.change_detectors,skchange.costs, ...) emits aFutureWarningin 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_predict(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.
Related Skills
mcp
Use the `mcp_perplexity-ask_perplexity_search` tools to answer questions. You should use this instead of the `web_search` tool because it is a lot more accurate.
practical-power-systems-synthesis
This skill enables synthesis in the domain of power-systems (engineering). It represents research-level-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform synthesis operations related to power-systems.
semi-supervised-optogenetics-testing
This skill enables testing in the domain of optogenetics (neuroscience). It represents intermediate-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform testing operations related to optogenetics.
data-mining-interpretation-fundamental
This skill enables interpretation in the domain of data-mining (data-science). It represents fundamental-level expertise and is designed for production use in research, industry, and educational contexts. Use this skill when you need to perform interpretation operations related to data-mining.
