Last active
June 29, 2020 15:40
-
-
Save sadimanna/634e19ec0c0cd400699e240473fa5bad to your computer and use it in GitHub Desktop.
This file contains hidden or 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 get_performance_metrics(y, pred, class_labels, tp=TP, tn=TN, fp=FP,fn=FN, | |
| acc=accuracy, spec=specificity, sens=sensitivity, | |
| ppv=ppv, npv=npv, auc=auc_score, f1=fscore, | |
| prevalence=prevalence, thresholds=[]): | |
| if len(thresholds) != len(class_labels): | |
| thresholds = [.5] * len(class_labels) | |
| func_dict = locals() | |
| func_keys = list(func_dict.keys()) | |
| columns = [""] | |
| for k in func_keys: | |
| columns.append(func_dict[k].__name__) | |
| df = pd.DataFrame(columns=columns) | |
| for i in range(len(class_labels)): | |
| df.loc[i] = [""] + [0] * (len(columns) - 1) | |
| df.loc[i][0] = class_labels[i] | |
| for j in range(1,len(columns)-1): | |
| if func_keys[j] == 'auc' or func_keys[j] == 'f1': | |
| df.loc[i][j] = round(func_dict[func_keys[j]](y[:, i], pred[:, i]), 3) if auc != None else "Not Defined" | |
| if func_keys[j] == 'prevalence': | |
| df.loc[i][j] = round(func_dict[func_keys[j]](y[:, i]), 3) if auc != None else "Not Defined" | |
| df.loc[i][j] = round(func_dict[func_keys[j]](y[:, i], pred[:, i], thresholds[i]), 3) if auc != None else "Not Defined" | |
| df.loc[i][len(columns)-1] = round(thresholds[i], 3) | |
| df = df.set_index("") | |
| return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment