コード例 #1
0
def test_classification_measurements():
    y_true = np.concatenate((np.ones(85), np.zeros(10), np.ones(5)))
    y_pred = np.concatenate((np.ones(90), np.zeros(10)))

    measurements = ClassificationMeasurements()
    for i in range(len(y_true)):
        measurements.add_result(y_true[i], y_pred[i])

    expected_acc = .9
    assert expected_acc == measurements.get_performance()

    expected_incorrectly_classified_ratio = 1 - expected_acc
    assert expected_incorrectly_classified_ratio == measurements.get_incorrectly_classified_ratio(
    )

    expected_kappa = (expected_acc - 0.82) / (1 - 0.82)
    assert np.isclose(expected_kappa, measurements.get_kappa())

    expected_kappa_m = (expected_acc - .1) / (1 - 0.1)
    assert np.isclose(expected_kappa_m, measurements.get_kappa_m())

    expected_kappa_t = (expected_acc - .97) / (1 - 0.97)
    assert expected_kappa_t == measurements.get_kappa_t()

    expected_info = 'ClassificationMeasurements: - sample_count: 100.0 - performance: 0.900000 - kappa: 0.444444 ' \
                    '- kappa_t: -2.333333 - kappa_m: 0.888889 - majority_class: 0'
    assert expected_info == measurements.get_info()

    expected_last = (1.0, 0.0)
    assert expected_last == measurements.get_last()

    expected_majority_class = 0
    assert expected_majority_class == measurements.get_majority_class()
コード例 #2
0
def test_classification_measurements():
    y_true = np.concatenate((np.ones(85), np.zeros(10), np.ones(5)))
    y_pred = np.concatenate((np.ones(90), np.zeros(10)))

    measurements = ClassificationMeasurements()
    for i in range(len(y_true)):
        measurements.add_result(y_true[i], y_pred[i])

    expected_acc = 90 / 100
    assert expected_acc == measurements.get_accuracy()

    expected_incorrectly_classified_ratio = 1 - expected_acc
    assert expected_incorrectly_classified_ratio == measurements.get_incorrectly_classified_ratio(
    )

    expected_kappa = (expected_acc - 0.82) / (1 - 0.82)
    assert np.isclose(expected_kappa, measurements.get_kappa())

    expected_kappa_m = (expected_acc - .9) / (1 - 0.9)
    assert np.isclose(expected_kappa_m, measurements.get_kappa_m())

    expected_kappa_t = (expected_acc - .97) / (1 - 0.97)
    assert expected_kappa_t == measurements.get_kappa_t()

    expected_precision = 85 / (85 + 5)
    assert np.isclose(expected_precision, measurements.get_precision())

    expected_recall = 85 / (85 + 5)
    assert np.isclose(expected_recall, measurements.get_recall())

    expected_f1_score = 2 * ((expected_precision * expected_recall) /
                             (expected_precision + expected_recall))
    assert np.isclose(expected_f1_score, measurements.get_f1_score())

    expected_g_mean = np.sqrt((5 / (5 + 5)) * expected_recall)
    assert np.isclose(expected_g_mean, measurements.get_g_mean())

    expected_info = 'ClassificationMeasurements: - sample_count: 100 - accuracy: 0.900000 - kappa: 0.444444 ' \
                    '- kappa_t: -2.333333 - kappa_m: 0.000000 - f1-score: 0.944444 - precision: 0.944444 ' \
                    '- recall: 0.944444 - g-mean: 0.687184 - majority_class: 1'
    assert expected_info == measurements.get_info()

    expected_last = (1.0, 0.0)
    assert expected_last == measurements.get_last()

    expected_majority_class = 1
    assert expected_majority_class == measurements.get_majority_class()

    measurements.reset()
    assert measurements.sample_count == 0
コード例 #3
0
def test_classification_measurements():
    y_true = np.concatenate((np.ones(85), np.zeros(10), np.ones(5)))
    y_pred = np.concatenate((np.ones(90), np.zeros(10)))

    measurements = ClassificationMeasurements()
    for i in range(len(y_true)):
        measurements.add_result(y_true[i], y_pred[i])

    expected_acc = .9
    assert expected_acc == measurements.get_accuracy()

    expected_incorrectly_classified_ratio = 1 - expected_acc
    assert expected_incorrectly_classified_ratio == measurements.get_incorrectly_classified_ratio(
    )

    expected_kappa = (expected_acc - 0.82) / (1 - 0.82)
    assert np.isclose(expected_kappa, measurements.get_kappa())

    expected_kappa_m = (expected_acc - .1) / (1 - 0.1)
    assert np.isclose(expected_kappa_m, measurements.get_kappa_m())

    expected_kappa_t = (expected_acc - .97) / (1 - 0.97)
    assert expected_kappa_t == measurements.get_kappa_t()

    expected_info = 'ClassificationMeasurements: - sample_count: 100 - accuracy: 0.900000 - kappa: 0.444444 ' \
                    '- kappa_t: -2.333333 - kappa_m: 0.888889 - f1-score: 0.500000 - ' \
                    'precision: 0.500000 - recall: 0.500000 - G-mean: 0.687184 - majority_class: 0'
    assert expected_info == measurements.get_info()

    expected_last = (1.0, 0.0)
    assert expected_last == measurements.get_last()

    expected_majority_class = 0
    assert expected_majority_class == measurements.get_majority_class()

    measurements.reset()
    assert measurements.sample_count == 0

    assert measurements.get_class_type() == 'measurement'