def accuracy_auc(y, ypred, weights=None): """Compute the accuracy, AUC, precision, recall and f1""" from mozsci.evaluation import classification_error, auc_wmw_fast, precision_recall_f1 prf1 = precision_recall_f1(y, ypred, weights=weights) return {'accuracy': 1.0 - classification_error(y, ypred, weights=weights), 'auc': auc_wmw_fast(y, ypred, weights=weights), 'precision': prf1[0], 'recall': prf1[1], 'f1': prf1[2]}
def test_auc_wmw_fast(self): t = [-1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, -1, 1] p = [0.01, 0.05, 0.2, 0.25, 0.1, 0.9, 0.6, 0.01, 0.90, 1.0, 0.33, 0.55, 0.555] auc_act = 0.54761904761904767 auc = evaluation.auc_wmw_fast(t, p) self.assertTrue(abs(auc_act - auc) < 1.0e-8)
def test_auc_wmw_fast(self): t = [-1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, -1, 1] p = [ 0.01, 0.05, 0.2, 0.25, 0.1, 0.9, 0.6, 0.01, 0.90, 1.0, 0.33, 0.55, 0.555 ] auc_act = 0.54761904761904767 auc = evaluation.auc_wmw_fast(t, p) self.assertTrue(abs(auc_act - auc) < 1.0e-8)
def test_auc_degenerate(self): y = np.array([0]) ypred = np.array([[ 1.0]]) weights = np.array([1]) auc = evaluation.auc_wmw_fast(y, ypred, weights=weights) self.assertTrue(auc == 0)
def agg_err(yactual, ypred): ret = {} ret['accuracy'] = classification_error(yactual, ypred) ret['auc'] = auc_wmw_fast(yactual, ypred) return ret
def test_auc_degenerate(self): y = np.array([0]) ypred = np.array([[1.0]]) weights = np.array([1]) auc = evaluation.auc_wmw_fast(y, ypred, weights=weights) self.assertTrue(auc == 0)