Skip to content

Commit

Permalink
fix(fit-method): Change the range of fitting exceedances (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: N. L <nino@pleno.earth>
  • Loading branch information
Aeternalis-Ingenium and ninopleno authored Dec 11, 2023
1 parent 51c47f5 commit f9c4ad4
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 527 deletions.
960 changes: 448 additions & 512 deletions docs/example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "anomalytics"
description = "The ultimate anomaly detection library."
readme = "README.md"
version = "0.1.4"
version = "0.1.5"
license = {file = "LICENSE"}
requires-python = ">=3.10"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/anomalytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.4"
__version__ = "0.1.5"

__all__ = [
"get_anomaly",
Expand Down
2 changes: 1 addition & 1 deletion src/anomalytics/models/peaks_over_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def plot(
alpha: float = 0.8,
):
if isinstance(self.__exceedance, pd.Series):
nonzero_exceedences = [exceedence for exceedence in self.__exceedance.values if exceedence > 0]
nonzero_exceedences = self.__exceedance[self.__exceedance.values > 0]
if plot_type == "l":
plot_line(
dataset=self.__dataset,
Expand Down
2 changes: 1 addition & 1 deletion src/anomalytics/stats/peaks_over_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_anomaly_score(ts: pd.Series, t0: int, gpd_params: typing.Dict) -> pd.Ser
t1_t2_exceedances = ts.iloc[t0:]

for row in range(0, t1_t2_exceedances.shape[0]):
fit_exceedances = ts.iloc[t0 + row :]
fit_exceedances = ts.iloc[: t0 + row]
future_exeedance = t1_t2_exceedances.iloc[row]
nonzero_fit_exceedances = fit_exceedances[fit_exceedances.values > 0.0]
if future_exeedance > 0:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_pkg_version():
assert __version__ == "0.1.4"
assert __version__ == "0.1.5"
20 changes: 10 additions & 10 deletions tests/unit/detectors/test_pot_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ def test_fit_with_genpareto_method(self):
self.pot1_detector.fit()

expected_anomaly_scores = pd.Series(
data=[1.922777880970598, 2.445890926224859, 3.6935717350888506, 3121651314.625431],
data=[float("inf"), float("inf"), float("inf"), float("inf")],
index=self.sample_1_ts.index[6:], # type: ignore
name="anomaly scores",
)
expected_params = {
0: {
"index": pd.Timestamp("2023-01-07 00:00:00"),
"c": -1.6804238287454643,
"c": -2.687778724221391,
"loc": 0,
"scale": 1.5123814458709186,
"p_value": 0.5200808735615424,
"anomaly_score": 1.922777880970598,
"scale": 1.3438893621106958,
"p_value": 0.0,
"anomaly_score": float("inf"),
},
}

Expand All @@ -78,7 +78,7 @@ def test_fit_with_genpareto_method(self):

def test_compute_anomaly_threshold_method(self):
expected_detected_data = [True]
expected_anomaly_threshold = 1.2394417670604552
expected_anomaly_threshold = 1.8927400332325932

self.pot2_detector.get_extremes(q=0.90)
self.pot2_detector.fit()
Expand All @@ -96,11 +96,11 @@ def test_evaluation_with_ks_1sample(self):
expected_kstest_result = pd.DataFrame(
data={
"total_nonzero_exceedances": [50],
"stats_distance": [0.8331661595029082],
"p_value": [4.312557311051241e-05],
"c": [-1.3371948412738648],
"stats_distance": [0.33333333326007464],
"p_value": [0.4234396436048128],
"c": [-1.5741853768217173],
"loc": [0],
"scale": [272179.457686573],
"scale": [71.62543464538814],
}
)

Expand Down

0 comments on commit f9c4ad4

Please sign in to comment.