def test_X_None(): X = None y = None from tests.mock_model import MockModel model = MockModel() models = [model] with pytest.raises(TypeError): eval_models(X, y, models)
def test_y_None(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy.txt') df = read_data(path) X = df[['value']] y = None from tests.mock_model import MockModel model = MockModel() models = [model] with pytest.raises(TypeError): eval_models(X, y, models)
def test_real_model(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy.txt') df = read_data(path) model = LatestWindowAnomalyDetector(alpha=0.05) models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models) print(res)
def test_eval_models_all_false(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy.txt') df = read_data(path) df['is_anomaly'] = 0 from tests.mock_model import MockModel model = MockModel(prediction=0) models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models) assert math.isnan(res['MockModel(prediction=0)']['f1']) assert math.isnan(res['MockModel(prediction=0)']['precision']) assert math.isnan(res['MockModel(prediction=0)']['recall'])
def test_n_splits_big(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy2.txt') df = read_data(path) from tests.mock_model import MockModel model = MockModel() models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models, n_splits=40000, verbose=True) assert res['MockModel(prediction=1)']['f1'] == 1.0 assert res['MockModel(prediction=1)']['precision'] == 1.0 assert res['MockModel(prediction=1)']['recall'] == 1.0
def test_eval_models_half_false(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy2.txt') df = read_data(path) df['is_anomaly'] = 0 df.iloc[-1]['is_anomaly'] = 1 df.iloc[-2]['is_anomaly'] = 1 from tests.mock_model import MockModel model = MockModel() models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models) assert res['MockModel(prediction=1)']['precision'] == 0.5 assert res['MockModel(prediction=1)']['recall'] == 1.0
def test_eval_models_all_true(): path = os.path.join(THIS_DIR, os.pardir, 'tests/dummy2.txt') df = read_data(path) from tests.mock_model import MockModel model = MockModel() models = [model] X = df[['value']] y = df[['is_anomaly']] res = eval_models(X, y, models) print(res) assert res['MockModel(prediction=1)']['f1'] == 1.0 assert res['MockModel(prediction=1)']['precision'] == 1.0 assert res['MockModel(prediction=1)']['recall'] == 1.0