def test_plot_roc_warning(self): prob = np.arange(0, 1, 0.1) result = pd.DataFrame({'pos': 1 - prob, 'neg': prob, 'Y_TRUE': ['pos'] * 9 + ['neg'], 'CV': [0, 1] * 5}) # re-enable logging because it is disabled in parent setUp logging.disable(logging.NOTSET) with self.assertLogs(level='WARNING') as cm: plot_roc(result) self.assertRegex(cm.output[0], 'no true positive or no negative samples')
def test_plot_roc_multi_no_cv(self): result = pd.read_table(join(self.test_data_dir, 'iris_pred.txt')) ax, _ = plot_roc(result, cv=False) legend = ax.get_legend() exp = { 'Luck', 'setosa (1.00)', 'virginica (0.94)', 'versicolor (0.92)' } obs = {i.get_text() for i in legend.get_texts()} self.assertSetEqual(exp, obs)
def test_plot_roc_multi(self): result = pd.read_table(join(self.test_data_dir, 'iris_pred.txt')) ax, _ = plot_roc(result) legend = ax.get_legend() exp = {'Luck', 'setosa (0.99 $\\pm$ 0.00)', 'virginica (0.96 $\\pm$ 0.05)', 'versicolor (0.95 $\\pm$ 0.07)'} obs = {i.get_text() for i in legend.get_texts()} self.assertSetEqual(exp, obs)
def test_plot_roc_warning(self): prob = np.arange(0, 1, 0.1) result = pd.DataFrame({ 'pos': 1 - prob, 'neg': prob, 'Y_TRUE': ['pos'] * 9 + ['neg'], 'CV': [0, 1] * 5 }) # re-enable logging because it is disabled in the parent setUp logging.disable(logging.NOTSET) # test for calour printed warning message with self.assertLogs(level='WARNING') as cm: # test (and capture) scikit-learn printed warning message with self.assertWarnsRegex( UserWarning, 'No positive samples in y_true, true positive value should be meaningless' ): plot_roc(result) self.assertRegex(cm.output[0], 'no true positive or no negative samples')
def test_plot_roc_binary(self): result = pd.read_table(join(self.test_data_dir, 'iris_pred.txt')) result['Y_TRUE'] = ['virginica' if i == 'virginica' else 'not virginica' for i in result['Y_TRUE']] result['not virginica'] = 1 - result['virginica'] ax, _ = plot_roc(result, classes=['virginica']) # from matplotlib import pyplot as plt # plt.show() legend = ax.get_legend() exp = {'Luck', 'virginica (0.96 $\\pm$ 0.05)'} obs = {i.get_text() for i in legend.get_texts()} self.assertSetEqual(exp, obs)