def test_user_warning_precision(): y_pred = np.array([0.04, 0.04, 0.10]) y_true = np.array([1., -1., 1.]) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") precision(y_true, y_pred) assert issubclass(w[-1].category, UserWarning) assert "sorting method used" in str(w[-1].message)
def test_non_trivial_precision_trapz(): y_pred = np.array([0.25, 0.45, 0.60, 0.90]) y_true = np.array([1., 1., 0., 1.]) prec = precision(y_true, y_pred) reference = np.array([1., 0.5, 2. / 3., 0.75]) assert (np.abs(prec - reference)).sum() < 1e-6