コード例 #1
0
def test_f1_cv_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    f1_scores = test_suite.f1_cv(3)
    assert isinstance(f1_scores, list)
    assert isinstance(f1_scores[0], float)
    assert len(f1_scores) == 3
コード例 #2
0
def test_cross_val_roc_auc_avg_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        avg = 0.1
        assert test_suite.cross_val_roc_auc_avg(avg)
    except ValueError:
        assert True
コード例 #3
0
def test_cross_val_roc_auc_anomaly_detection_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        tolerance = 1
        assert test_suite.cross_val_roc_auc_anomaly_detection(tolerance)
    except ValueError:
        assert True
コード例 #4
0
def test_cross_val_f1_avg_multiclass():
    df, column_names, target_name, clf, _ = generate_multiclass_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        avg = 0.1
        test_suite.cross_val_f1_avg(avg, average="micro")
        assert True
    except:
        assert False
コード例 #5
0
def test_cross_val_recall_avg_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        avg = 0.1
        test_suite.cross_val_recall_avg(avg)
        assert True
    except:
        assert False
コード例 #6
0
def test_cross_val_f1_anomaly_detection_mutliclass():
    df, column_names, target_name, clf, _ = generate_multiclass_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        tolerance = 1
        test_suite.cross_val_f1_anomaly_detection(tolerance, average="micro")
        assert True
    except:
        assert False
コード例 #7
0
def test_cross_val_recall_anomaly_detection_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        tolerance = 1
        test_suite.cross_val_recall_anomaly_detection(tolerance)
        assert True
    except:
        assert False
コード例 #8
0
def test_spread_cross_val_f1_anomaly_detection_multiclass():
    df, column_names, target_name, clf, _ = generate_multiclass_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    tolerance = 1
    assert test_suite.spread_cross_val_f1_anomaly_detection(tolerance)
    assert test_suite.spread_cross_val_f1_anomaly_detection(tolerance,
                                                            method="median")
    assert test_suite.spread_cross_val_f1_anomaly_detection(tolerance,
                                                            method="trimean")
コード例 #9
0
def test_roc_auc_cv_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        roc_auc_scores = test_suite.roc_auc_cv(3)
        assert isinstance(roc_auc_scores, list)
        assert isinstance(roc_auc_scores[0], float)
        assert len(roc_auc_scores) == 3
    except ValueError:
        assert True
コード例 #10
0
def test_run_time_stress_test():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    sample_sizes = [i for i in range(100, 1000, 100)]
    max_run_times = [100 for _ in range(len(sample_sizes))]
    try:
        test_suite.run_time_stress_test(sample_sizes, max_run_times)
        assert True
    except:
        assert False
コード例 #11
0
def test_precision_recall_f1_multiclass():
    df, column_names, target_name, clf, _ = generate_multiclass_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    classes = list(df.target.unique())
    assert test_suite.classifier_testing({klass: 0.1
                                          for klass in classes},
                                         {klass: 0.1
                                          for klass in classes},
                                         {klass: 0.1
                                          for klass in classes})
コード例 #12
0
def test_run_time_stress_test():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    performance_boundary = []
    for i in range(100, 1000, 100):
        performance_boundary.append({"sample_size": i, "max_run_time": 100})
    try:
        test_suite.run_time_stress_test(performance_boundary)
        assert True
    except:
        assert False
コード例 #13
0
def test_spread_cross_val_roc_auc_anomaly_detection_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        tolerance = 1
        test_suite.spread_cross_val_roc_auc_anomaly_detection(tolerance)
        test_suite.spread_cross_val_roc_auc_anomaly_detection(tolerance,
                                                              method="median")
        test_suite.spread_cross_val_roc_auc_anomaly_detection(tolerance,
                                                              method="trimean")
        assert True
    except:
        assert False
コード例 #14
0
def test_precision_recall_f1_binary():
    df, column_names, target_name, clf, _ = generate_binary_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        classes = list(df[target_name].unique())
        test_suite.classifier_testing({klass: 0.1
                                       for klass in classes},
                                      {klass: 0.1
                                       for klass in classes},
                                      {klass: 0.1
                                       for klass in classes})
        assert True
    except:
        assert False
コード例 #15
0
def test():
    df = pd.read_csv("data.csv")
    column_names = ["A", "B", "C"]
    target_name = "target"
    clf = joblib.load("model1.joblib")

    test_suite = classification_tests.ClassificationTests(clf,
                                                          df,
                                                          target_name,
                                                          column_names)
    classes = list(df.target.unique())
    assert test_suite.classifier_testing(
        {klass: 0.9 for klass in classes},
        {klass: 0.9 for klass in classes},
        {klass: 0.9 for klass in classes}
    )
コード例 #16
0
def test_spread_cross_val_precision_anomaly_detection_multiclass():
    df, column_names, target_name, clf, _ = generate_multiclass_classification_data_and_models(
    )
    test_suite = classification_tests.ClassificationTests(
        clf, df, target_name, column_names)
    try:
        tolerance = 1
        average = "micro"
        test_suite.spread_cross_val_precision_anomaly_detection(
            tolerance, average=average)
        test_suite.spread_cross_val_precision_anomaly_detection(
            tolerance, method="median", average=average)
        test_suite.spread_cross_val_precision_anomaly_detection(
            tolerance, method="trimean", average=average)
        assert True
    except:
        assert False