Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Created March 1, 2021 05:47
Show Gist options
  • Save RicherMans/e3014313e2e8942f7cd943b0428e40f6 to your computer and use it in GitHub Desktop.
Save RicherMans/e3014313e2e8942f7cd943b0428e40f6 to your computer and use it in GitHub Desktop.
Metrics for SED evaluation
import numpy as np
import sklearn.metrics as skmetrics
from scipy import stats
def roc(y_true, y_pred, average=None):
return skmetrics.roc_auc_score(y_true, y_pred, average=average)
def mAP(y_true, y_pred, average=None):
return skmetrics.average_precision_score(y_true, y_pred, average=average)
def d_prime(auc):
return stats.norm().ppf(auc) * np.sqrt(2.0)
y_true = np.array([0,1,1,1])
y_pred = np.array([0.5,0.2,0.1,0.8])
mAP = np.nan_to_num(mAP(y_true, y_pred))
auc = np.nan_to_num(roc(y_true, y_pred))
dprime = np.nan_to_num(d_prime(np.mean(auc)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment