def test_curves_from_results(self, init): res = Results() ytrue, probs = self.data.T res.actual = ytrue.astype(float) res.probabilities = np.vstack((1 - probs, probs)).T.reshape(1, -1, 2) Curves.from_results(res) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue) np.testing.assert_equal(cprobs, probs) Curves.from_results(res, target_class=0) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, 1 - ytrue) np.testing.assert_equal(cprobs, 1 - probs) res.actual = ytrue.astype(float) res.probabilities = np.random.random((2, 19, 2)) res.probabilities[1] = np.vstack((1 - probs, probs)).T Curves.from_results(res, model_index=1) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue) np.testing.assert_equal(cprobs, probs) self.assertRaises(ValueError, Curves.from_results, res) ytrue[ytrue == 0] = 2 * (np.arange(10) % 2) res.actual = ytrue.astype(float) res.probabilities = np.random.random((2, 19, 3)) res.probabilities[1] = np.vstack( ((1 - probs) / 3, probs, (1 - probs) * 2 / 3)).T Curves.from_results(res, model_index=1, target_class=1) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue == 1) np.testing.assert_equal(cprobs, probs) Curves.from_results(res, model_index=1, target_class=0) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue == 0) np.testing.assert_equal(cprobs, (1 - probs) / 3) Curves.from_results(res, model_index=1, target_class=2) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue == 2) np.testing.assert_equal(cprobs, (1 - probs) * 2 / 3) self.assertRaises(ValueError, Curves.from_results, res, model_index=1)
def test_empty_results(self): """Test on empty results.""" res = Results(data=self.iris[:0], store_data=True) res.row_indices = np.array([], dtype=int) res.actual = np.array([]) res.predicted = np.array([[]]) res.probabilities = np.zeros((1, 0, 3)) self.send_signal(self.widget.Inputs.evaluation_results, res) self.widget.select_correct() self.widget.select_wrong()
def test_nan_results(self): """Test on results with nan values in actual/predicted""" res = Results(data=self.iris, nmethods=2, store_data=True) res.row_indices = np.array([0, 50, 100], dtype=int) res.actual = np.array([0., np.nan, 2.]) res.predicted = np.array([[np.nan, 1, 2], [np.nan, np.nan, np.nan]]) res.probabilities = np.zeros((1, 3, 3)) self.send_signal(self.widget.Inputs.evaluation_results, res) self.assertTrue(self.widget.Error.invalid_values.is_shown()) self.send_signal(self.widget.Inputs.evaluation_results, None) self.assertFalse(self.widget.Error.invalid_values.is_shown())
def test_curves_from_results_nans(self, init): res = Results() ytrue, probs = self.data.T ytrue[0] = np.nan probs[-1] = np.nan res.actual = ytrue.astype(float) res.probabilities = np.vstack((1 - probs, probs)).T.reshape(1, -1, 2) Curves.from_results(res) cytrue, cprobs = init.call_args[0] np.testing.assert_equal(cytrue, ytrue[1:-1]) np.testing.assert_equal(cprobs, probs[1:-1])