Created
June 29, 2019 03:40
-
-
Save zhpmatrix/149c1db43aa5c8820c506a7a6347656d to your computer and use it in GitHub Desktop.
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
from sklearn.metrics import f1_score, precision_recall_fscore_support, classification_report | |
def evaluation(real_labels, pred_labels): | |
f1_micro = f1_score(real_labels, pred_labels, average='micro') | |
f1_macro = f1_score(real_labels, pred_labels, average='macro') | |
f1_weighted = f1_score(real_labels, pred_labels, average='weighted') | |
#f1_binary = f1_score(real_labels, pred_labels, average='binary') | |
#f1_samples = f1_score(real_labels, pred_labels, average='samples') | |
micro_p, micro_r, micro_f1, _ = precision_recall_fscore_support(real_labels, pred_labels, average='micro') | |
macro_p, macro_r, macro_f1, _ = precision_recall_fscore_support(real_labels, pred_labels, average='macro') | |
report = classification_report(real_labels, pred_labels) | |
print('f1 micro: ',f1_micro) | |
print('f1 macro: ',f1_macro) | |
print('f1 weighted: ',f1_weighted) | |
#print('f1 binary: ',f1_binary) | |
#print('f1 samples: ',f1_samples) | |
print('micro p, micro r, micro f1:', micro_p, micro_r, micro_f1) | |
print('macro p, macro r, macro f1:', macro_p, macro_r, macro_f1) | |
print(report) | |
if __name__ == '__main__': | |
real_labels = [1,1,1,2,3,3,3,3] | |
pred_labels = [1,1,2,2,1,3,1,2] | |
evaluation(real_labels, pred_labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment