Download src/evalmetrics.py from Nabidnur/AIP-AD: direct link, hf CLI and curl.
- Browser
- Download file 830 Bytes
-
https://huggingface.co/Nabidnur/AIP-AD/resolve/main/src/evalmetrics.py
- Command line
-
hf download hf://Nabidnur/AIP-AD/src/evalmetrics.py
-
curl -L -o evalmetrics.py https://huggingface.co/Nabidnur/AIP-AD/resolve/main/src/evalmetrics.py
830 Bytes
| """Metrics and experiment result containers.""" | |
| from __future__ import annotations | |
| import numpy as np | |
| from sklearn.metrics import roc_auc_score | |
| def auroc(scores, labels): | |
| scores = np.asarray(scores, dtype=np.float64) | |
| labels = np.asarray(labels) | |
| if len(np.unique(labels)) < 2: | |
| return float("nan") | |
| return float(roc_auc_score(labels, scores)) | |
| def sample_auroc_table(view_scores, labels, cats): | |
| """Fixed-strategy S-AUROC per category + macro. Returns dict.""" | |
| from .fusion import fuse_all | |
| fused = fuse_all(view_scores) | |
| res = {} | |
| for name, s in fused.items(): | |
| per = {} | |
| for cat in np.unique(cats): | |
| m = cats == cat | |
| per[cat] = auroc(s[m], labels[m]) | |
| per["macro"] = float(np.nanmean(list(per.values()))) | |
| res[name] = per | |
| return res | |