Beispiel #1
0
def test_cbm_zero_input_lengths():
    cbm = CostBenefitMatrix(true_positive=10,
                            true_negative=-1,
                            false_positive=-7,
                            false_negative=-2)
    y_predicted = pd.Series([])
    y_true = pd.Series([])
    with pytest.raises(ValueError, match="Length of inputs is 0"):
        cbm.score(y_true, y_predicted)
Beispiel #2
0
def test_cbm_different_input_lengths():
    cbm = CostBenefitMatrix(true_positive=10,
                            true_negative=-1,
                            false_positive=-7,
                            false_negative=-2)
    y_predicted = pd.Series([0, 0])
    y_true = pd.Series([1])
    with pytest.raises(ValueError, match="Inputs have mismatched dimensions"):
        cbm.score(y_true, y_predicted)

    y_true = pd.Series([0, 0])
    y_predicted = pd.Series([1, 2, 0])
    with pytest.raises(ValueError, match="Inputs have mismatched dimensions"):
        cbm.score(y_true, y_predicted)
Beispiel #3
0
def test_cbm_input_contains_nan(X_y_binary):
    y_predicted = pd.Series([np.nan, 0, 0])
    y_true = pd.Series([1, 2, 1])
    cbm = CostBenefitMatrix(true_positive=10,
                            true_negative=-1,
                            false_positive=-7,
                            false_negative=-2)
    with pytest.raises(ValueError,
                       match="y_predicted contains NaN or infinity"):
        cbm.score(y_true, y_predicted)

    y_true = pd.Series([np.nan, 0, 0])
    y_predicted = pd.Series([1, 2, 0])
    with pytest.raises(ValueError, match="y_true contains NaN or infinity"):
        cbm.score(y_true, y_predicted)
Beispiel #4
0
def test_cbm_input_contains_inf(capsys):
    cbm = CostBenefitMatrix(true_positive=10,
                            true_negative=-1,
                            false_positive=-7,
                            false_negative=-2)
    y_predicted = np.array([np.inf, 0, 0])
    y_true = np.array([1, 0, 0])
    with pytest.raises(ValueError,
                       match="y_predicted contains NaN or infinity"):
        cbm.score(y_true, y_predicted)

    y_true = pd.Series([np.inf, 0, 0])
    y_predicted = pd.Series([1, 0, 0])
    with pytest.raises(ValueError, match="y_true contains NaN or infinity"):
        cbm.score(y_true, y_predicted)
Beispiel #5
0
def test_cbm_binary_more_than_two_unique_values():
    cbm = CostBenefitMatrix(true_positive=10,
                            true_negative=-1,
                            false_positive=-7,
                            false_negative=-2)
    y_predicted = pd.Series([0, 1, 2])
    y_true = pd.Series([1, 0, 1])
    with pytest.raises(
            ValueError,
            match="y_predicted contains more than two unique values"):
        cbm.score(y_true, y_predicted)

    y_true = pd.Series([0, 1, 2])
    y_predicted = pd.Series([1, 0, 1])
    with pytest.raises(ValueError,
                       match="y_true contains more than two unique values"):
        cbm.score(y_true, y_predicted)