Isolation Forest anomaly detection for timestamped sensor CSV data
Project description
anomaly-watcher
CLI tool for Isolation Forest based anomaly detection on timestamped sensor CSV files.
Slides a rolling window over sensor signals, extracts 9 statistical features per sensor (mean, std, min, max, slope, last value, difference std, skewness, kurtosis) plus elapsed time, trains a two-pass Isolation Forest on the training set (first pass discards outlier training windows above a cleanup quantile), then scores test windows against a configurable threshold. The final scoring pass runs --forests-number Isolation Forest instances (default: 3), uses the mean score per window for thresholding, and plots the mean plus a shaded +/- 1 std band. Three threshold modes are available: max (max score * relief margin), quantile (score quantile), and std (mean + std * relief margin).
Sensor columns are auto-detected as numeric, boolean, or categorical. CSV rows with missing values are dropped. The output is a 6-panel overview PNG (raw features, z-score features, and anomaly scores for train and test) with anomalous test windows highlighted. Optional score CSV output includes the mean anomaly score, per-window score standard deviation, and one score column per forest run.
Usage
anomaly-watcher --train train.csv --test test.csv --output anomaly_overview.png
Both CSV files must contain a timestamp column and the same signal columns. Signal columns may be numeric, logical/boolean, or categorical strings. Rows with missing values after conversion are removed.
Run anomaly-watcher --help for all options. The companion command anomaly-watcher-template copies the template CSV to a target directory for quick project setup.
Local dashboard
The lightweight local dashboard can be launched with:
anomaly-watcher-dashboard
The dashboard starts from a local project configuration. New projects choose one mode:
batch: train and test with CSV files.real-time: train from an initial CSV, then monitor incoming stream data such as MQTT JSON messages.
By default, the dashboard proposes a project folder named anomaly_watcher_project under the directory where you launched the dashboard. If launched from the repo root, that resolves to C:\Users\apoli\Documents\GitHub\python-tools\anomaly_watcher_project. The Project Setup page shows the resolved absolute folder before saving.
The first dashboard milestone includes project setup, batch CSV detection, a CSV replay incoming-data inspector, and scheduled retraining settings placeholders. Continuous MQTT and OPC UA integrations are planned behind the same source interface.
Mock data
Example CSV files are included under src/anomaly_watcher/resources/:
mock_training.csvmock_test.csv
They contain numeric, boolean, and categorical signal columns and can be used for a quick package test. The test file includes a clear injected anomaly where Temp_bed drops strongly while Temp_tool0 and Humidity rise sharply.
anomaly-watcher --train src/anomaly_watcher/resources/mock_training.csv --test src/anomaly_watcher/resources/mock_test.csv --output mock_overview.png --save-scores mock_scores.csv --plot-sensor Temp_bed --window-seconds 10 --stride-seconds 4 --forests-number 3 --relief-margin 0
With these compact demo settings, the mock test set should produce confirmed anomalous windows around the injected fault segment.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anomaly_watcher-0.1.0.tar.gz.
File metadata
- Download URL: anomaly_watcher-0.1.0.tar.gz
- Upload date:
- Size: 37.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17cfa8ae5db2cf57c3fc9b040ce074317a7222f144ed62c838cf0f11ad4aa9ac
|
|
| MD5 |
2099c947376bb965c0b15e1a8bdd7b18
|
|
| BLAKE2b-256 |
90a853dbc0452348b2904f95ff479c23d8ad8af98bb70924971478e8e9bc9d49
|
Provenance
The following attestation bundles were made for anomaly_watcher-0.1.0.tar.gz:
Publisher:
anomaly-watcher-build-publish.yml on ricardo-cunha/python-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anomaly_watcher-0.1.0.tar.gz -
Subject digest:
17cfa8ae5db2cf57c3fc9b040ce074317a7222f144ed62c838cf0f11ad4aa9ac - Sigstore transparency entry: 2136961311
- Sigstore integration time:
-
Permalink:
ricardo-cunha/python-tools@7162f4c1c8066afc5df6596aeb3221e88ef3e4f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ricardo-cunha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
anomaly-watcher-build-publish.yml@7162f4c1c8066afc5df6596aeb3221e88ef3e4f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file anomaly_watcher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: anomaly_watcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23bbec9f3b16b42749236eb77bbd511cf6c240832db61ea37b95485ddd800778
|
|
| MD5 |
7151a503e1482ecb06cbd646d94c51fc
|
|
| BLAKE2b-256 |
593d3fdd5057b801b0d34e485f9a05212993d8096429cbc5b94ce22b173be945
|
Provenance
The following attestation bundles were made for anomaly_watcher-0.1.0-py3-none-any.whl:
Publisher:
anomaly-watcher-build-publish.yml on ricardo-cunha/python-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anomaly_watcher-0.1.0-py3-none-any.whl -
Subject digest:
23bbec9f3b16b42749236eb77bbd511cf6c240832db61ea37b95485ddd800778 - Sigstore transparency entry: 2136961447
- Sigstore integration time:
-
Permalink:
ricardo-cunha/python-tools@7162f4c1c8066afc5df6596aeb3221e88ef3e4f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ricardo-cunha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
anomaly-watcher-build-publish.yml@7162f4c1c8066afc5df6596aeb3221e88ef3e4f0 -
Trigger Event:
push
-
Statement type: