Skip to content

Instantly share code, notes, and snippets.

@tengpeng
Created February 26, 2016 19:11
Show Gist options
  • Save tengpeng/c5ee4de4cd8891bb5c55 to your computer and use it in GitHub Desktop.
Save tengpeng/c5ee4de4cd8891bb5c55 to your computer and use it in GitHub Desktop.
backup m1
def mf(y_true, y_pred):
tp = 0
fp = 0
fn = 0
for i in range(y_true.shape[0]):
for j in range(y_true.shape[1]):
if y_true[i, j] == y_pred[i, j]:
if y_true[i,j] == 1:
tp += 1
elif y_true[i, j] != y_pred[i, j]:
if y_pred[i,j] == 1:
fp += 1
else:
fn += 1
p = tp/(tp + fp + 0.0001)
r = tp/(tp + fn + 0.0001)
f = 2*(p*r)/(p + r + 0.0001)
return f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment