コード例 #1
0
ファイル: test_latest_window.py プロジェクト: shaypal5/fossa
def test_base():
    num_categ = 8
    clf = LatestWindowAnomalyDetector(alpha=0.00001)
    history = dummy_data(num_days=10,
                         num_categories=num_categ,
                         min_val=100,
                         max_val=1000)
    new_day = dummy_data(num_days=1,
                         num_categories=num_categ,
                         min_val=100,
                         max_val=1000)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]

    num_new_days = 30
    many_days = dummy_data(num_days=num_new_days,
                           num_categories=num_categ,
                           min_val=100,
                           max_val=1000)
    predictions = clf.predict(many_days)
    assert len(predictions) == num_categ * num_new_days
    for x in predictions.values:
        assert x in [-1, 0, 1]
コード例 #2
0
ファイル: test_last_n_windows.py プロジェクト: shaypal5/fossa
def test_partial_fit():
    num_categ = 8
    clf = LastNWindowsAnomalyDetector(
        n_windows=4,
        weights=uniform_weighter(),
        alpha=0.001,
    )
    history = dummy_data(num_days=10,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    recent_history = dummy_data(num_days=6,
                                num_categories=num_categ,
                                min_val=1000,
                                max_val=1200)
    new_day = dummy_data(num_days=1,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    clf.fit(history)
    clf.partial_fit(recent_history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #3
0
ファイル: test_last_n_windows.py プロジェクト: shaypal5/fossa
def test_exp_comp_weighter():
    num_categ = 8
    n_windows = 4
    clf = LastNWindowsAnomalyDetector(
        n_windows=n_windows,
        weights=exp_comp_weighter(n=n_windows, concave_factor=1),
        alpha=0.001,
    )
    history = dummy_data(num_days=10,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    new_day = dummy_data(num_days=1,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]

    clf = LastNWindowsAnomalyDetector(
        n_windows=n_windows,
        weights=exp_comp_weighter(n=n_windows, concave_factor=3),
        alpha=0.001,
    )
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]

    clf = LastNWindowsAnomalyDetector(
        n_windows=n_windows,
        weights=exp_comp_weighter(n=n_windows, concave_factor=30),
        alpha=0.001,
    )
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]

    clf = LastNWindowsAnomalyDetector(
        n_windows=n_windows,
        weights=exp_comp_weighter(n=n_windows, concave_factor=None),
        alpha=0.001,
    )
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #4
0
ファイル: test_latest_window.py プロジェクト: omri374/fossa
def test_non_def_ddof():
    num_categ = 8
    clf = LatestWindowAnomalyDetector(p_threshold=0.00001, power=-2, ddof=4)
    history = dummy_data(
        num_days=10, num_categories=num_categ, min_val=100, max_val=1000)
    new_day = dummy_data(
        num_days=1, num_categories=num_categ, min_val=100, max_val=1000)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #5
0
ファイル: test_latest_window.py プロジェクト: omri374/fossa
def test_diff_categ():
    num_categ_1 = 8
    num_categ_2 = 7
    clf = LatestWindowAnomalyDetector(p_threshold=0.00001)
    history = dummy_data(
        num_days=10, num_categories=num_categ_1, min_val=100, max_val=1000)
    new_day = dummy_data(
        num_days=1, num_categories=num_categ_2, min_val=100, max_val=1000)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == max(num_categ_1, num_categ_2)
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #6
0
ファイル: test_latest_window.py プロジェクト: omri374/fossa
def test_partial_fit():
    num_categ = 8
    clf = LatestWindowAnomalyDetector(p_threshold=0.00001)
    history = dummy_data(
        num_days=10, num_categories=num_categ, min_val=100, max_val=1000)
    recent_history = dummy_data(
        num_days=6, num_categories=num_categ, min_val=100, max_val=1000)
    new_day = dummy_data(
        num_days=1, num_categories=num_categ, min_val=100, max_val=1000)
    clf.fit(history)
    clf.partial_fit(recent_history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #7
0
ファイル: test_last_n_windows.py プロジェクト: shaypal5/fossa
def test_errors():
    # bad p thresholds
    with pytest.raises(ValueError):
        LastNWindowsAnomalyDetector(
            n_windows=4,
            weights=uniform_weighter(),
            alpha=2,
        )
    # bad p thresholds
    with pytest.raises(ValueError):
        LastNWindowsAnomalyDetector(
            n_windows=4,
            weights=uniform_weighter(),
            alpha=-1,
        )
    clf = LastNWindowsAnomalyDetector(
        n_windows=4,
        weights=uniform_weighter(),
        alpha=0.001,
    )
    new_day = dummy_data(num_days=1,
                         num_categories=8,
                         min_val=1000,
                         max_val=1200)
    with pytest.raises(NotFittedError):
        clf.predict(new_day)
コード例 #8
0
ファイル: test_last_n_windows.py プロジェクト: shaypal5/fossa
def test_weights_function():
    num_categ = 8
    clf = LastNWindowsAnomalyDetector(
        n_windows=6,
        weights=_weight_by_inverse_days_delta,
        alpha=0.001,
    )
    history = dummy_data(num_days=10,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    new_day = dummy_data(num_days=1,
                         num_categories=num_categ,
                         min_val=1000,
                         max_val=1200)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == num_categ
    for x in prediction.values:
        assert x in [-1, 0, 1]
コード例 #9
0
ファイル: test_latest_window.py プロジェクト: omri374/fossa
def test_errors():
    # bad p thresholds
    with pytest.raises(ValueError):
        LatestWindowAnomalyDetector(p_threshold=2)
    # bad p thresholds
    with pytest.raises(ValueError):
        LatestWindowAnomalyDetector(p_threshold=-1)
    clf = LatestWindowAnomalyDetector(p_threshold=0.00001)
    new_day = dummy_data(
        num_days=1, num_categories=8, min_val=100, max_val=1000)
    with pytest.raises(NotFittedError):
        clf.predict(new_day)
コード例 #10
0
ファイル: test_last_n_windows.py プロジェクト: shaypal5/fossa
def test_diff_categ():
    num_categ_1 = 8
    num_categ_2 = 7
    clf = LastNWindowsAnomalyDetector(
        n_windows=4,
        weights=uniform_weighter(),
        alpha=0.001,
    )
    history = dummy_data(num_days=10,
                         num_categories=num_categ_1,
                         min_val=1000,
                         max_val=1200)
    new_day = dummy_data(num_days=1,
                         num_categories=num_categ_2,
                         min_val=1000,
                         max_val=1200)
    clf.fit(history)
    prediction = clf.predict(new_day)
    assert len(prediction) == max(num_categ_1, num_categ_2)
    for x in prediction.values:
        assert x in [-1, 0, 1]