ChandraPrakashBathula commited on
Commit
bb799f3
·
verified ·
1 Parent(s): 5dcf987

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -49,17 +49,30 @@ def metrics_markdown():
49
  if not p.exists():
50
  return "_metrics.json not found._"
51
  m = json.loads(p.read_text())
52
- out = [
53
- f"**Test accuracy:** {m['test_accuracy']:.2%}  ·  "
54
- f"**Macro F1:** {m['macro_f1']:.3f}  ·  "
55
- f"**Best val accuracy:** {m['best_val_accuracy']:.2%}  ·  "
56
- f"**Parameters:** {m['params']:,}",
57
- "",
58
- "| Class | Precision | Recall | F1 | Test images |",
59
- "|---|---|---|---|---|",
60
- ]
61
- for c, r in m["per_class"].items():
62
- out.append(f"| {c} | {r['precision']:.3f} | {r['recall']:.3f} | {r['f1-score']:.3f} | {int(r['support'])} |")
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  return "\n".join(out)
64
 
65
  PLOTS = [
 
49
  if not p.exists():
50
  return "_metrics.json not found._"
51
  m = json.loads(p.read_text())
52
+ cm = np.array(m["confusion_matrix"])
53
+ tp = cm.diagonal()
54
+ precision = tp / cm.sum(axis=0).clip(min=1)
55
+ recall = tp / cm.sum(axis=1).clip(min=1)
56
+ f1 = 2 * precision * recall / (precision + recall + 1e-12)
57
+
58
+ head = [f"**Test accuracy:** {m['test_accuracy']:.2%}",
59
+ f"**Macro F1:** {m['macro_f1']:.3f}"]
60
+ if m.get("best_val_accuracy"):
61
+ head.append(f"**Best val accuracy:** {m['best_val_accuracy']:.2%}")
62
+ if m.get("params"):
63
+ head.append(f"**Parameters:** {m['params']:,}")
64
+
65
+ out = ["  ·  ".join(head), "",
66
+ "| Class | Precision | Recall | F1 | Test images |",
67
+ "|---|---|---|---|---|"]
68
+ for i, c in enumerate(CLASSES):
69
+ out.append(f"| {c} | {precision[i]:.3f} | {recall[i]:.3f} | {f1[i]:.3f} | {cm[i].sum()} |")
70
+
71
+ # top confusions
72
+ off = [(cm[i, j], CLASSES[i], CLASSES[j]) for i in range(len(CLASSES))
73
+ for j in range(len(CLASSES)) if i != j]
74
+ out += ["", "**Most confused (actual → predicted):** " +
75
+ ", ".join(f"{a} → {b} ({n})" for n, a, b in sorted(off, reverse=True)[:4])]
76
  return "\n".join(out)
77
 
78
  PLOTS = [