def test_y_true_labels_float(self): test_val = self.empc_test_val y = [float(l) for l in self.y_true] yhat = self.y_score params = self.empc_params emp = EMPChurn(y_true=y, y_score=yhat, **params) empc = emp.empc() self.assertAlmostEqual(empc, test_val)
def test_y_true_labels_str(self): test_val = self.empc_test_val y = ["yes" if y_lbl == 1 else "no" for y_lbl in self.y_true] yhat = self.y_score params = self.empc_params params["case_label"] = "yes" emp = EMPChurn(y_true=y, y_score=yhat, **params) empc = emp.empc() self.assertAlmostEqual(empc, test_val)
def test_empc_y_score_method(self): """Test EMPC is computed correctly: y_score given as method input.""" test_val = self.empc_test_val y = self.y_true yhat = self.y_score params = self.empc_params emp = EMPChurn(y_true=y, **params) empc = emp.empc(y_score=yhat) self.assertAlmostEqual(empc, test_val)
def test_empc_y_score_instantiation(self): """Test EMPC is computed correctly: y_score given at instantiation.""" test_val = self.empc_test_val y = self.y_true yhat = self.y_score params = self.empc_params emp = EMPChurn(y_true=y, y_score=yhat, **params) empc = emp.empc() self.assertAlmostEqual(empc, test_val)
def test_repeated_empc_computation(self): """ Test EMPC is computed correctly: Repeated computation with same object. """ test_val = 30.3003222629848 y = np.asarray(self.y_true) yhat = np.array(self.y_score) params = self.empc_params obj = EMPChurn(y_true=y, **params) empc1 = obj.empc(y_score=yhat) self.assertAlmostEqual(empc1, test_val) empc2 = obj.empc() self.assertAlmostEqual(empc2, test_val) yhat[0] = 0.287577520124614 empc3 = obj.empc(y_score=yhat) self.assertAlmostEqual(empc3, 30.3001182343737) yhat[6] = 0.113703411305323 empc4 = obj.empc(y_score=yhat) self.assertAlmostEqual(empc4, 29.2002764792561)