Last active
January 6, 2017 06:22
-
-
Save himkt/0664d8aefa40a3f7193ef4829b758258 to your computer and use it in GitHub Desktop.
sensitivityとかspecificityとか,classification_reportが計算してくれないやつを計算するためにTP, TN, FP, FNが必要
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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