Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ats/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import pandas as pd
from copy import deepcopy

def _format_for_anomaly_detector(input_df,synthetic=False):
def _format_for_anomaly_detector(df,synthetic=False):
if synthetic:
input_df.drop(columns=['effect_label'],inplace=True)
if 'anomaly_label' not in input_df.columns:
df = df.drop(columns=['effect_label'],inplace=False)
if 'anomaly_label' not in df.columns:
raise ValueError('The input DataFrame has to contain an "anomaly_label" column for evaluation')

anomaly_labels = input_df.loc[:,'anomaly_label']
input_df.drop(columns=['anomaly_label'],inplace=True)
return input_df,anomaly_labels
anomaly_labels = df.loc[:,'anomaly_label']
df = df.drop(columns=['anomaly_label'],inplace=False)
return df,anomaly_labels

def evaluate_anomaly_detector(evaluated_timeseries_df, anomaly_labels, details=False):

Expand Down
20 changes: 20 additions & 0 deletions ats/tests/test_evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,23 @@ def test_series_granularity_evaluation(self):
evaluation_result2 = _series_granularity_evaluation(flagged_series2,anomaly_labels2)
except Exception as e:
self.assertIsInstance(e,ValueError)

def test_double_evaluator(self):
anomalies = ['step_uv']
effects = []
series_generator = HumiTempTimeseriesGenerator()
# series1 will be a true anomaly for the minmax
series1 = series_generator.generate(anomalies=anomalies,effects=effects)
# series2 will be a false positive for minmax (it sees always 2 anomalous data points for each variable)
series2 = series_generator.generate(anomalies=[],effects=effects)
dataset = [series1,series2]
evaluator = Evaluator(test_data=dataset)
minmax1 = MinMaxAnomalyDetector()
minmax2 = MinMaxAnomalyDetector()
minmax3 = MinMaxAnomalyDetector()
models={'detector_1': minmax1,
'detector_2': minmax2,
'detector_3': minmax3
}
evaluation_results = evaluator.evaluate(models=models,granularity='series')
evaluation_results = evaluator.evaluate(models=models,granularity='series')