def test_y_None(): path = os.path.join(THIS_DIR, os.pardir, 'tests/data/dummy.txt') df = read_data(path) X = df[['value']] y = None model = MockModel() models = [model] with pytest.raises(TypeError): eval_models(X, y, models, label_col_name='is_anomaly')
def test_X_None(): X = None y = None model = MockModel() models = [model] try: res = eval_models(X, y, models, label_col_name='is_anomaly') except TypeError: assert True return assert False
def test_real_model(): path = os.path.join(THIS_DIR, os.pardir, 'tests/data/dummy.txt') df = read_data(path) model = MovingAverageSeasonalTrendinessDetector(is_multicategory=True, freq='12H') models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models, label_col_name='is_anomaly') print(res)
def test_eval_models_all_false(): path = os.path.join(THIS_DIR, os.pardir, 'tests/data/dummy.txt') df = read_data(path) df['is_anomaly'] = 0 model = MockModel() models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models, label_col_name='is_anomaly') assert math.isnan(res['MockModel']['f1']) assert res['MockModel']['precision'] == 0 assert math.isnan(res['MockModel']['recall'])
def test_eval_models_half_false(): path = os.path.join(THIS_DIR, os.pardir, 'tests/data/dummy2.txt') df = read_data(path) df['is_anomaly'] = 0 df.iloc[-1]['is_anomaly'] = 1 df.iloc[-2]['is_anomaly'] = 1 model = MockModel() models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models, label_col_name='is_anomaly', window_size_for_metrics=0) assert res['MockModel']['precision'] == 0.5 assert res['MockModel']['recall'] == 1.0