Skip to content

Instantly share code, notes, and snippets.

@himkt
Last active January 6, 2017 06:22
Show Gist options
  • Save himkt/0664d8aefa40a3f7193ef4829b758258 to your computer and use it in GitHub Desktop.
Save himkt/0664d8aefa40a3f7193ef4829b758258 to your computer and use it in GitHub Desktop.
sensitivityとかspecificityとか,classification_reportが計算してくれないやつを計算するためにTP, TN, FP, FNが必要
def compute_clf(confusion_matrix: numpy.ndarray, classes: list):
"""
return TP, TN, FP, FN followed by the order of classes
shape: (n_classes, 4)
"""
ret = list()
total = confusion_matrix.sum()
for index, _class in enumerate(classes):
row_sum = confusion_matrix[index, :].sum()
column_sum = confusion_matrix[:, index].sum()
tp = confusion_matrix[index, index]
fn = row_sum - tp
fp = column_sum - tp
tn = total - row_sum - column_sum + tp
ret.append([tp, tn, fp, fn])
ret = numpy.asarray(ret)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment