def test_compare_bootstrap_failures(self): with self.assertRaises(ValueError): compare_bootstrap(self.roc1, self.roc2, seed=-1) for wrong_hypo in [-10, -0.01, 1.01, 10]: with self.assertRaises(ValueError): compare_bootstrap(self.roc1, self.roc2, alt_hypothesis=wrong_hypo)
def test_compare_bootstrap_extreme_alt_hypothesis(self): result = compare_bootstrap(self.roc1, self.roc1, alt_hypothesis=0.0, seed=37) assert not result[0] result = compare_bootstrap(self.roc2, self.roc1, alt_hypothesis=1.0, seed=37) assert result[1]
def test_compare_bootstrap_simple(self): result = compare_bootstrap(self.roc1, self.roc2, seed=37) assert result[0] assert np.isclose(result[1], 0.04163033112351611) result = compare_bootstrap(self.roc2, self.roc1, seed=37) assert not result[0] assert np.isclose(result[1], 1 - 0.04163033112351611) result = compare_bootstrap(self.roc1, self.roc2, alt_hypothesis=0.01, seed=37) assert not result[0] result2 = compare_bootstrap(self.roc1, self.roc2, seed=42) assert result[1] != result2[1]
def __lt__(self, other: Any) -> bool: if not isinstance(other, type(self)): raise NotImplementedError # Import here to avoid cross reference imports from pyroc import compare_bootstrap comb_p_value = 1 - max(self.statistical_power, other.statistical_power) return compare_bootstrap(self, other, seed=37, alt_hypothesis=comb_p_value)[0]
"""Simple example how to compare two ROC curves.""" import numpy as np from pyroc import ROC, compare_bootstrap, compare_binary # Simple example to test bootstrap ex_rng = np.random.RandomState(37) num = 100 ex_gt = ex_rng.binomial(1, 0.5, num) ex_est = ex_rng.rand((num)) ex_roc1 = ROC(ex_gt, ex_est) ex_roc2 = ROC([True, True, True, False, False, False], [.9, .8, .35, .4, .3, .1]) print(compare_bootstrap(ex_roc1, ex_roc2, seed=37)) print(compare_binary(ex_roc1, ex_roc2, seed=37)) print(compare_bootstrap(ex_roc1, ex_roc1, seed=37)) print(compare_binary(ex_roc1, ex_roc1, seed=37)) print(ex_roc1 < ex_roc2) print(ex_roc1 <= ex_roc2) print(ex_roc1 > ex_roc2) print(ex_roc1 >= ex_roc2) print(ex_roc1 == ex_roc2)