This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TDD to false positives with test case to validate if model can…
… learn from false positives
- Loading branch information
Zak Hassan
committed
May 16, 2019
1 parent
5bac71d
commit 3d31608
Showing
7 changed files
with
333,067 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,6 @@ | ||
LS_INPUT_PATH: "/Users/zhassan/git/log-anomaly-detector/validation_data/log_anomaly_detector-100000-events.json" | ||
LS_OUTPUT_PATH: "/Users/zhassan/git/log-anomaly-detector/validation_data/local-results-1.txt" | ||
INFER_TIME_SPAN: 1 | ||
INFER_LOOPS: 1 | ||
INFER_ANOMALY_THRESHOLD: 0.1 | ||
PARALLELISM: 6 |
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 |
---|---|---|
|
@@ -32,6 32,7 @@ pyyaml = "*" | |
Flask-SQLAlchemy = "*" | ||
PyMySQL = "*" | ||
|
||
|
||
[requires] | ||
python_version = "3.6" | ||
|
||
|
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,40 @@ | ||
import pytest | ||
from anomaly_detector.anomaly_detector import AnomalyDetector | ||
from anomaly_detector.config import Configuration | ||
import json | ||
from pandas.io.json import json_normalize | ||
|
||
import numpy as np | ||
CONFIGURATION_PREFIX = "LAD" | ||
|
||
|
||
@pytest.fixture() | ||
def detector(): | ||
config = Configuration(prefix=CONFIGURATION_PREFIX, config_yaml=".test_env_config.yaml") | ||
anomaly_detector = AnomalyDetector(config) | ||
return anomaly_detector | ||
|
||
|
||
def test_false_positive(detector, benchmark): | ||
""" | ||
Testing False Positives and feeding it into the model | ||
""" | ||
# TODO: Increase the frequency of the false anomalies | ||
FALSE_POSITIVE = [{"message": "(root) CMD (/usr/local/bin/monitor-apache-stats.sh >/dev/null 2>&1)"}] | ||
FALSE_POSITIVE2 = [{"message": "(root) CMD (/usr/local/bin/monitor-apache-stats.sh >/dev/null 2>&1)"}] * 10000 | ||
buffer=[] | ||
fp = json_normalize(FALSE_POSITIVE) | ||
fp2 = json_normalize(FALSE_POSITIVE2) | ||
success, dist = detector.train(fp=fp) | ||
print(np.mean(dist), np.std(dist), np.max(dist), np.min(dist)) | ||
num=dist[-1] | ||
buffer.append(num) | ||
success, dist = detector.train(fp=fp2) | ||
print(np.mean(dist), np.std(dist), np.max(dist), np.min(dist)) | ||
num2=dist[-1] | ||
buffer.append(num2) | ||
print(buffer) | ||
print("Second Training Run: Finished") | ||
found=True | ||
|
||
assert found is True |
Oops, something went wrong.