Ejemplo n.º 1
0
def test_read_data():
    path = os.path.join(THIS_DIR, os.pardir, 'test/dummy.txt')
    df = read_data(path)
    index = df.index
    # assert index is pd.MultiIndex
    assert len(df) == 16
    assert isinstance(df.index, pd.MultiIndex)
Ejemplo n.º 2
0
def test_y_None():
    path = os.path.join(THIS_DIR, os.pardir, 'test/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')
Ejemplo n.º 3
0
def test_real_model():
    path = os.path.join(THIS_DIR, os.pardir, 'test/dummy.txt')
    df = read_data(path)
    model = StlTrendinessDetector(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)
Ejemplo n.º 4
0
def test_n_splits_big():
    path = os.path.join(THIS_DIR, os.pardir, 'test/dummy2.txt')
    df = read_data(path)

    model = MockModel()
    models = [model]
    X = df[['value']]
    y = df[['is_anomaly']]
    res = eval_models_CV(X, y, models, n_splits=40000,verbose=True ,label_col_name='is_anomaly')
    assert res['MockModel']['f1'] == 1.0
    assert res['MockModel']['precision'] == 1.0
    assert res['MockModel']['recall'] == 1.0
Ejemplo n.º 5
0
def test_eval_models_all_false():
    path = os.path.join(THIS_DIR, os.pardir, 'test/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'])
Ejemplo n.º 6
0
def test_eval_models_half_false():
    path = os.path.join(THIS_DIR, os.pardir, 'test/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