-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from NorskRegnesentral/binary_segmentation
Add Binary Segmentation type algorithms
- Loading branch information
Showing
21 changed files
with
1,367 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import plotly.express as px | ||
from streamchange.utils import Profiler | ||
|
||
from skchange.anomaly_detectors.circular_binseg import ( | ||
CircularBinarySegmentation, | ||
make_anomaly_intervals, | ||
) | ||
from skchange.datasets.generate import teeth | ||
|
||
df = teeth(n_segments=3, mean=10, segment_length=20, p=1, random_state=7) | ||
detector = CircularBinarySegmentation( | ||
score="mean", growth_factor=1.5, min_segment_length=10 | ||
) | ||
anomalies = detector.fit_predict(df) | ||
|
||
df.plot(kind="line", backend="plotly") | ||
|
||
px.scatter(detector.scores, x="argmax_anomaly_start", y="score") | ||
|
||
# Test anomaly intervals | ||
anomaly_intervals = make_anomaly_intervals(0, 5, 2) | ||
|
||
# Profiling | ||
n = int(1e5) | ||
df = teeth(n_segments=1, mean=0, segment_length=n, p=1) | ||
detector = CircularBinarySegmentation("mean", growth_factor=1.5) | ||
profiler = Profiler() | ||
profiler.start() | ||
detector.fit_predict(df) | ||
profiler.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import plotly.express as px | ||
from streamchange.utils import Profiler | ||
|
||
from skchange.change_detectors.seeded_binseg import SeededBinarySegmentation | ||
from skchange.datasets.generate import teeth | ||
|
||
df = teeth(n_segments=2, mean=10, segment_length=20, p=1, random_state=7) | ||
detector = SeededBinarySegmentation(score="mean", growth_factor=2) | ||
detector.fit_predict(df) | ||
|
||
df.plot(kind="line", backend="plotly") | ||
|
||
px.scatter(detector.scores, x="maximizer", y="score", hover_data=["start", "end"]) | ||
|
||
|
||
# Profiling | ||
n = int(1e6) | ||
df = teeth(n_segments=1, mean=0, segment_length=n, p=1) | ||
detector = SeededBinarySegmentation("mean", growth_factor=1.5, min_segment_length=10) | ||
profiler = Profiler() | ||
profiler.start() | ||
detector.fit_predict(df) | ||
profiler.stop() | ||
|
||
|
||
# Test tuning | ||
df_train = teeth(n_segments=1, mean=0, segment_length=10000, p=1, random_state=9) | ||
df_test = teeth(n_segments=10, mean=5, segment_length=1000, p=1, random_state=5) | ||
detector = SeededBinarySegmentation( | ||
score="mean", threshold_scale=None, min_segment_length=10 | ||
) | ||
detector.fit(df_train) | ||
changepoints = detector.predict(df_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.