Mercurial > repos > goeckslab > image_learner
annotate plotly_plots.py @ 15:d17e3a1b8659 draft default tip
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
| author | goeckslab |
|---|---|
| date | Fri, 28 Nov 2025 15:45:49 +0000 |
| parents | c5150cceab47 |
| children |
| rev | line source |
|---|---|
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
1 import json |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
2 from pathlib import Path |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
3 from typing import Dict, List, Optional |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
4 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
5 import numpy as np |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
6 import pandas as pd |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
7 import plotly.graph_objects as go |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
8 import plotly.io as pio |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
9 from constants import LABEL_COLUMN_NAME, SPLIT_COLUMN_NAME |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
10 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
11 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
12 def _style_fig(fig: go.Figure, font_size: int = 12) -> go.Figure: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
13 """Apply consistent styling across Plotly figures.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
14 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
15 font=dict(size=font_size), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
16 plot_bgcolor="#ffffff", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
17 paper_bgcolor="#ffffff", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
18 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
19 fig.update_xaxes(gridcolor="#e8e8e8") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
20 fig.update_yaxes(gridcolor="#e8e8e8") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
21 return fig |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
22 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
23 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
24 def _labels_from_metadata_dict(meta_dict: dict) -> List[str]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
25 """Extract ordered label names from Ludwig train_set_metadata.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
26 if not isinstance(meta_dict, dict): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
27 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
28 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
29 for key in ("idx2str", "idx2label", "vocab"): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
30 seq = meta_dict.get(key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
31 if isinstance(seq, list) and seq: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
32 return [str(v) for v in seq] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
33 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
34 str2idx = meta_dict.get("str2idx") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
35 if isinstance(str2idx, dict) and str2idx: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
36 int_indices = [v for v in str2idx.values() if isinstance(v, int)] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
37 if int_indices: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
38 max_idx = max(int_indices) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
39 ordered = [None] * (max_idx + 1) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
40 for name, idx in str2idx.items(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
41 if isinstance(idx, int) and 0 <= idx < len(ordered): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
42 ordered[idx] = name |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
43 return [str(v) for v in ordered if v is not None] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
44 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
45 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
46 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
47 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
48 def _resolve_confusion_labels( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
49 label_stats: dict, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
50 n_classes: int, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
51 metadata_csv_path: Optional[str], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
52 train_set_metadata_path: Optional[str], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
53 ) -> List[str]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
54 """Prefer original labels from metadata; fall back to stats if unavailable.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
55 if train_set_metadata_path: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
56 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
57 meta_path = Path(train_set_metadata_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
58 if meta_path.exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
59 with open(meta_path, "r") as f: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
60 meta_json = json.load(f) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
61 label_meta = meta_json.get(LABEL_COLUMN_NAME) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
62 if not isinstance(label_meta, dict): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
63 label_meta = next( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
64 ( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
65 v |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
66 for v in meta_json.values() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
67 if isinstance(v, dict) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
68 and any(k in v for k in ("idx2str", "str2idx", "idx2label", "vocab")) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
69 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
70 None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
71 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
72 labels_from_meta = _labels_from_metadata_dict(label_meta) if label_meta else [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
73 if labels_from_meta and len(labels_from_meta) >= n_classes: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
74 return [str(label) for label in labels_from_meta[:n_classes]] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
75 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
76 print(f"Warning: Unable to read labels from train_set_metadata: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
77 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
78 if metadata_csv_path: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
79 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
80 csv_path = Path(metadata_csv_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
81 if csv_path.exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
82 df_meta = pd.read_csv(csv_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
83 if LABEL_COLUMN_NAME in df_meta.columns: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
84 uniques = df_meta[LABEL_COLUMN_NAME].dropna().unique().tolist() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
85 if uniques and len(uniques) >= n_classes: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
86 return [str(u) for u in uniques[:n_classes]] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
87 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
88 print(f"Warning: Unable to read labels from metadata CSV: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
89 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
90 pcs = label_stats.get("per_class_stats", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
91 if pcs: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
92 pcs_labels = [str(k) for k in pcs.keys()] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
93 if len(pcs_labels) >= n_classes: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
94 return pcs_labels[:n_classes] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
95 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
96 labels = label_stats.get("labels") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
97 if not labels: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
98 labels = [str(i) for i in range(n_classes)] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
99 if len(labels) < n_classes: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
100 labels = labels + [str(i) for i in range(len(labels), n_classes)] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
101 return [str(label) for label in labels[:n_classes]] |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
102 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
103 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
104 def build_classification_plots( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
105 test_stats_path: str, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
106 training_stats_path: Optional[str] = None, |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
107 metadata_csv_path: Optional[str] = None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
108 train_set_metadata_path: Optional[str] = None, |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
109 ) -> List[Dict[str, str]]: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
110 """ |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
111 Read Ludwig’s test_statistics.json and build three interactive Plotly panels: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
112 - Confusion Matrix |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
113 - ROC-AUC |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
114 - Classification Report Heatmap |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
115 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
116 If metadata paths are provided, the confusion matrix axes will use the original |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
117 label values from the training metadata rather than integer-encoded labels. |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
118 |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
119 Returns a list of dicts, each with: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
120 { |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
121 "title": <plot title>, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
122 "html": <HTML fragment for embedding> |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
123 } |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
124 """ |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
125 # --- Load test stats --- |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
126 with open(test_stats_path, "r") as f: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
127 test_stats = json.load(f) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
128 label_stats = test_stats["label"] |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
129 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
130 # common sizing |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
131 cell = 40 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
132 n_classes = len(label_stats["confusion_matrix"]) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
133 side_px = max(cell * n_classes + 200, 600) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
134 common_cfg = {"displayModeBar": True, "scrollZoom": True} |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
135 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
136 plots: List[Dict[str, str]] = [] |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
137 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
138 # 0) Confusion Matrix |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
139 cm = np.array(label_stats["confusion_matrix"], dtype=int) |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
140 labels = _resolve_confusion_labels( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
141 label_stats, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
142 n_classes, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
143 metadata_csv_path=metadata_csv_path, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
144 train_set_metadata_path=train_set_metadata_path, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
145 ) |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
146 total = cm.sum() |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
147 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
148 fig_cm = go.Figure( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
149 go.Heatmap( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
150 z=cm, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
151 x=labels, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
152 y=labels, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
153 colorscale="Blues", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
154 showscale=True, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
155 colorbar=dict(title="Count"), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
156 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
157 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
158 fig_cm.update_traces(xgap=2, ygap=2) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
159 fig_cm.update_layout( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
160 title=dict(text="Confusion Matrix", x=0.5), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
161 xaxis_title="Predicted", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
162 yaxis_title="Observed", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
163 yaxis_autorange="reversed", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
164 width=side_px, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
165 height=side_px, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
166 margin=dict(t=100, l=80, r=80, b=80), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
167 ) |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
168 _style_fig(fig_cm) |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
169 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
170 # annotate counts and percentages |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
171 mval = cm.max() if cm.size else 0 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
172 thresh = mval / 2 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
173 for i in range(cm.shape[0]): |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
174 for j in range(cm.shape[1]): |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
175 v = cm[i, j] |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
176 pct = (v / total * 100) if total > 0 else 0 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
177 color = "white" if v > thresh else "black" |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
178 fig_cm.add_annotation( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
179 x=labels[j], |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
180 y=labels[i], |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
181 text=f"<b>{v}</b>", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
182 showarrow=False, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
183 font=dict(color=color, size=14), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
184 xanchor="center", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
185 yanchor="bottom", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
186 yshift=2, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
187 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
188 fig_cm.add_annotation( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
189 x=labels[j], |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
190 y=labels[i], |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
191 text=f"{pct:.1f}%", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
192 showarrow=False, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
193 font=dict(color=color, size=13), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
194 xanchor="center", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
195 yanchor="top", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
196 yshift=-2, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
197 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
198 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
199 plots.append({ |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
200 "title": "Confusion Matrix", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
201 "html": pio.to_html( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
202 fig_cm, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
203 full_html=False, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
204 include_plotlyjs="cdn", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
205 config=common_cfg |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
206 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
207 }) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
208 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
209 # 1) ROC Curve (from test_statistics) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
210 roc_plot = _build_static_roc_plot(label_stats, common_cfg, friendly_labels=labels) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
211 if roc_plot: |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
212 plots.append(roc_plot) |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
213 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
214 # 2) Precision-Recall Curve (from test_statistics) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
215 pr_plot = _build_precision_recall_plot(label_stats, common_cfg) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
216 if pr_plot: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
217 plots.append(pr_plot) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
218 |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
219 # 2) Classification Report Heatmap |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
220 pcs = label_stats.get("per_class_stats", {}) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
221 if pcs: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
222 classes = list(pcs.keys()) |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
223 metrics = [ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
224 "precision", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
225 "recall", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
226 "f1_score", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
227 "accuracy", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
228 "matthews_correlation_coefficient", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
229 "specificity", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
230 ] |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
231 z, txt = [], [] |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
232 for c in classes: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
233 row, trow = [], [] |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
234 for m in metrics: |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
235 val = pcs[c].get(m, 0) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
236 row.append(val) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
237 trow.append(f"{val:.2f}") |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
238 z.append(row) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
239 txt.append(trow) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
240 |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
241 fig_cr = go.Figure( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
242 go.Heatmap( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
243 z=z, |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
244 x=[m.replace("_", " ") for m in metrics], |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
245 y=[str(c) for c in classes], |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
246 text=txt, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
247 texttemplate="%{text}", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
248 colorscale="Reds", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
249 showscale=True, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
250 colorbar=dict(title="Value"), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
251 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
252 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
253 fig_cr.update_layout( |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
254 title="Per-Class metrics", |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
255 xaxis_title="", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
256 yaxis_title="Class", |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
257 width=side_px, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
258 height=side_px, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
259 margin=dict(t=80, l=80, r=80, b=80), |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
260 ) |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
261 _style_fig(fig_cr) |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
262 plots.append({ |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
263 "title": "Per-Class metrics", |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
264 "html": pio.to_html( |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
265 fig_cr, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
266 full_html=False, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
267 include_plotlyjs=False, |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
268 config=common_cfg |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
269 ) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
270 }) |
|
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
271 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
272 # 3) Prediction Diagnostics (from predictions.csv) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
273 # Note: appended separately in generate_html_report, not returned here. |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
274 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
275 return plots |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
276 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
277 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
278 def build_train_validation_plots(train_stats_path: str) -> List[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
279 """Generate Train/Validation learning curve plots from training_statistics.json.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
280 if not train_stats_path or not Path(train_stats_path).exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
281 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
282 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
283 with open(train_stats_path, "r") as f: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
284 train_stats = json.load(f) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
285 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
286 print(f"Warning: Unable to read training statistics: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
287 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
288 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
289 label_train = (train_stats.get("training") or {}).get("label", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
290 label_val = (train_stats.get("validation") or {}).get("label", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
291 if not label_train and not label_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
292 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
293 plots: List[Dict[str, str]] = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
294 include_js = True # Load Plotly.js once for this group |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
295 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
296 def _get_series(stats: dict, metric: str) -> List[float]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
297 if metric not in stats: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
298 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
299 vals = stats.get(metric, []) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
300 if isinstance(vals, list): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
301 return [float(v) for v in vals] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
302 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
303 return [float(vals)] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
304 except Exception: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
305 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
306 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
307 def _line_plot(metric_key: str, title: str, yaxis_title: str) -> Optional[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
308 train_series = _get_series(label_train, metric_key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
309 val_series = _get_series(label_val, metric_key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
310 if not train_series and not val_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
311 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
312 epochs_train = list(range(1, len(train_series) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
313 epochs_val = list(range(1, len(val_series) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
314 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
315 if train_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
316 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
317 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
318 x=epochs_train, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
319 y=train_series, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
320 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
321 name="Train", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
322 line=dict(width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
323 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
324 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
325 if val_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
326 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
327 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
328 x=epochs_val, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
329 y=val_series, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
330 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
331 name="Validation", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
332 line=dict(width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
333 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
334 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
335 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
336 title=dict(text=title, x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
337 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
338 yaxis_title=yaxis_title, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
339 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
340 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
341 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
342 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
343 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
344 return { |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
345 "title": title, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
346 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
347 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
348 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
349 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
350 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
351 } |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
352 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
353 # Core learning curves |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
354 for key, title in [ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
355 ("roc_auc", "ROC-AUC across epochs"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
356 ("precision", "Precision across epochs"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
357 ("recall", "Recall/Sensitivity across epochs"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
358 ("specificity", "Specificity across epochs"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
359 ]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
360 plot = _line_plot(key, title, title.replace("Learning Curve", "").strip()) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
361 if plot: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
362 plots.append(plot) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
363 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
364 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
365 # Precision vs Recall evolution (validation) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
366 val_prec = _get_series(label_val, "precision") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
367 val_rec = _get_series(label_val, "recall") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
368 if val_prec and val_rec: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
369 epochs = list(range(1, min(len(val_prec), len(val_rec)) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
370 fig_pr = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
371 fig_pr.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
372 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
373 x=epochs, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
374 y=val_prec[: len(epochs)], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
375 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
376 name="Precision", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
377 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
378 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
379 fig_pr.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
380 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
381 x=epochs, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
382 y=val_rec[: len(epochs)], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
383 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
384 name="Recall", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
385 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
386 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
387 fig_pr.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
388 title=dict(text="Validation Precision and Recall by Epoch", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
389 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
390 yaxis_title="Value", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
391 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
392 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
393 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
394 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
395 _style_fig(fig_pr) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
396 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
397 "title": "Precision vs Recall Evolution", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
398 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
399 fig_pr, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
400 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
401 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
402 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
403 }) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
404 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
405 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
406 # F1-score derived |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
407 def _compute_f1(p: List[float], r: List[float]) -> List[float]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
408 f1_vals = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
409 for prec, rec in zip(p, r): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
410 if (prec + rec) == 0: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
411 f1_vals.append(0.0) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
412 else: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
413 f1_vals.append(2 * prec * rec / (prec + rec)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
414 return f1_vals |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
415 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
416 f1_train = _compute_f1(_get_series(label_train, "precision"), _get_series(label_train, "recall")) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
417 f1_val = _compute_f1(val_prec, val_rec) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
418 if f1_train or f1_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
419 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
420 if f1_train: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
421 fig.add_trace(go.Scatter(x=list(range(1, len(f1_train) + 1)), y=f1_train, mode="lines+markers", name="Train", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
422 if f1_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
423 fig.add_trace(go.Scatter(x=list(range(1, len(f1_val) + 1)), y=f1_val, mode="lines+markers", name="Validation", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
424 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
425 title=dict(text="F1-Score across epochs (derived)", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
426 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
427 yaxis_title="F1-Score", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
428 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
429 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
430 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
431 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
432 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
433 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
434 "title": "F1-Score across epochs (derived)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
435 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
436 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
437 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
438 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
439 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
440 }) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
441 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
442 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
443 # Overfitting Gap: Train vs Val ROC-AUC (gap) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
444 roc_train = _get_series(label_train, "roc_auc") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
445 roc_val = _get_series(label_val, "roc_auc") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
446 if roc_train and roc_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
447 epochs_gap = list(range(1, min(len(roc_train), len(roc_val)) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
448 gaps = [t - v for t, v in zip(roc_train[:len(epochs_gap)], roc_val[:len(epochs_gap)])] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
449 fig_gap = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
450 fig_gap.add_trace(go.Scatter(x=epochs_gap, y=gaps, mode="lines+markers", name="Train - Val ROC-AUC", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
451 fig_gap.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
452 title=dict(text="Overfitting gap: ROC-AUC across epochs", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
453 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
454 yaxis_title="Gap", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
455 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
456 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
457 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
458 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
459 _style_fig(fig_gap) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
460 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
461 "title": "Overfitting gap: ROC-AUC across epochs", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
462 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
463 fig_gap, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
464 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
465 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
466 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
467 }) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
468 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
469 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
470 # Best Epoch Dashboard (based on max val ROC-AUC) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
471 if roc_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
472 best_idx = int(np.argmax(roc_val)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
473 best_epoch = best_idx + 1 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
474 spec_val = _get_series(label_val, "specificity") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
475 metrics_at_best = { |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
476 "ROC-AUC": roc_val[best_idx] if best_idx < len(roc_val) else None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
477 "Precision": val_prec[best_idx] if best_idx < len(val_prec) else None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
478 "Recall": val_rec[best_idx] if best_idx < len(val_rec) else None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
479 "Specificity": spec_val[best_idx] if best_idx < len(spec_val) else None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
480 "F1-Score": f1_val[best_idx] if best_idx < len(f1_val) else None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
481 } |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
482 fig_best = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
483 for name, value in metrics_at_best.items(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
484 if value is not None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
485 fig_best.add_trace(go.Bar(name=name, x=[name], y=[value])) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
486 fig_best.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
487 title=dict(text=f"Best Epoch Dashboard (Val ROC-AUC @ epoch {best_epoch})", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
488 xaxis_title="Metric", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
489 yaxis_title="Value", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
490 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
491 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
492 showlegend=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
493 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
494 _style_fig(fig_best) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
495 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
496 "title": "Best Validation Epoch Snapshot (Metrics)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
497 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
498 fig_best, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
499 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
500 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
501 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
502 }) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
503 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
504 |
|
8
85e6f4b2ad18
planemo upload for repository https://github.com/goeckslab/gleam.git commit 8a42eb9b33df7e1df5ad5153b380e20b910a05b6
goeckslab
parents:
diff
changeset
|
505 return plots |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
506 |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
507 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
508 def _get_regression_series(split_stats: dict, metric: str) -> List[float]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
509 if metric not in split_stats: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
510 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
511 vals = split_stats.get(metric, []) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
512 if isinstance(vals, list): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
513 return [float(v) for v in vals] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
514 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
515 return [float(vals)] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
516 except Exception: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
517 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
518 |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
519 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
520 def _regression_line_plot( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
521 train_split: dict, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
522 val_split: dict, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
523 metric_key: str, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
524 title: str, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
525 yaxis_title: str, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
526 include_js: bool, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
527 ) -> Optional[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
528 train_series = _get_regression_series(train_split, metric_key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
529 val_series = _get_regression_series(val_split, metric_key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
530 if not train_series and not val_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
531 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
532 epochs_train = list(range(1, len(train_series) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
533 epochs_val = list(range(1, len(val_series) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
534 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
535 if train_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
536 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
537 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
538 x=epochs_train, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
539 y=train_series, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
540 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
541 name="Train", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
542 line=dict(width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
543 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
544 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
545 if val_series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
546 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
547 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
548 x=epochs_val, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
549 y=val_series, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
550 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
551 name="Validation", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
552 line=dict(width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
553 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
554 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
555 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
556 title=dict(text=title, x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
557 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
558 yaxis_title=yaxis_title, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
559 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
560 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
561 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
562 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
563 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
564 return { |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
565 "title": title, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
566 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
567 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
568 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
569 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
570 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
571 } |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
572 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
573 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
574 def build_regression_train_val_plots(train_stats_path: str) -> List[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
575 """Generate regression Train/Validation learning curve plots from training_statistics.json.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
576 if not train_stats_path or not Path(train_stats_path).exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
577 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
578 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
579 with open(train_stats_path, "r") as f: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
580 train_stats = json.load(f) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
581 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
582 print(f"Warning: Unable to read training statistics: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
583 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
584 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
585 label_train = (train_stats.get("training") or {}).get("label", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
586 label_val = (train_stats.get("validation") or {}).get("label", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
587 if not label_train and not label_val: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
588 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
589 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
590 plots: List[Dict[str, str]] = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
591 include_js = True |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
592 for metric_key, title, ytitle in [ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
593 ("mean_absolute_error", "Mean Absolute Error across epochs", "MAE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
594 ("root_mean_squared_error", "Root Mean Squared Error across epochs", "RMSE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
595 ("mean_absolute_percentage_error", "Mean Absolute Percentage Error across epochs", "MAPE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
596 ("r2", "R² across epochs", "R²"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
597 ("loss", "Loss across epochs", "Loss"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
598 ]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
599 plot = _regression_line_plot(label_train, label_val, metric_key, title, ytitle, include_js) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
600 if plot: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
601 plots.append(plot) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
602 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
603 return plots |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
604 |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
605 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
606 def build_regression_test_plots(train_stats_path: str) -> List[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
607 """Generate regression Test learning curves from training_statistics.json.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
608 if not train_stats_path or not Path(train_stats_path).exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
609 return [] |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
610 try: |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
611 with open(train_stats_path, "r") as f: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
612 train_stats = json.load(f) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
613 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
614 print(f"Warning: Unable to read training statistics: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
615 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
616 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
617 label_test = (train_stats.get("test") or {}).get("label", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
618 if not label_test: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
619 return [] |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
620 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
621 plots: List[Dict[str, str]] = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
622 include_js = True |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
623 metrics = [ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
624 ("mean_absolute_error", "Mean Absolute Error Across Epochs", "MAE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
625 ("root_mean_squared_error", "Root Mean Squared Error Across Epochs", "RMSE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
626 ("mean_absolute_percentage_error", "Mean Absolute Percentage Error Across Epochs", "MAPE"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
627 ("r2", "R² Across Epochs", "R²"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
628 ("loss", "Loss Across Epochs", "Loss"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
629 ] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
630 epochs = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
631 for metric_key, title, ytitle in metrics: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
632 series = _get_regression_series(label_test, metric_key) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
633 if not series: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
634 continue |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
635 if epochs is None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
636 epochs = list(range(1, len(series) + 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
637 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
638 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
639 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
640 x=epochs, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
641 y=series[: len(epochs)], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
642 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
643 name="Test", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
644 line=dict(width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
645 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
646 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
647 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
648 title=dict(text=title, x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
649 xaxis_title="Epoch", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
650 yaxis_title=ytitle, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
651 width=760, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
652 height=520, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
653 hovermode="x unified", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
654 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
655 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
656 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
657 "title": title, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
658 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
659 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
660 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
661 include_plotlyjs="cdn" if include_js else False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
662 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
663 }) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
664 include_js = False |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
665 return plots |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
666 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
667 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
668 def _build_static_roc_plot( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
669 label_stats: dict, config: dict, friendly_labels: Optional[List[str]] = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
670 ) -> Optional[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
671 """Build ROC curve directly from test_statistics.json (single curve).""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
672 roc_data = label_stats.get("roc_curve") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
673 if not isinstance(roc_data, dict): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
674 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
675 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
676 fpr = roc_data.get("false_positive_rate") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
677 tpr = roc_data.get("true_positive_rate") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
678 if not fpr or not tpr or len(fpr) != len(tpr): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
679 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
680 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
681 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
682 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
683 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
684 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
685 x=fpr, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
686 y=tpr, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
687 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
688 name="ROC Curve", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
689 line=dict(color="#1f77b4", width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
690 hovertemplate="FPR: %{x:.3f}<br>TPR: %{y:.3f}<extra></extra>", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
691 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
692 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
693 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
694 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
695 x=[0, 1], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
696 y=[0, 1], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
697 mode="lines", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
698 name="Random Classifier", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
699 line=dict(color="gray", width=2, dash="dash"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
700 hovertemplate="Random Classifier<extra></extra>", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
701 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
702 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
703 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
704 auc_val = label_stats.get("roc_auc") or label_stats.get("roc_auc_macro") or label_stats.get("roc_auc_micro") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
705 auc_txt = f" (AUC = {auc_val:.3f})" if isinstance(auc_val, (int, float)) else "" |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
706 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
707 # Determine which label is treated as positive for the curve |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
708 label_list: List = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
709 pcs = label_stats.get("per_class_stats", {}) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
710 if pcs: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
711 label_list = list(pcs.keys()) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
712 if not label_list: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
713 labels_from_stats = label_stats.get("labels") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
714 if isinstance(labels_from_stats, list): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
715 label_list = labels_from_stats |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
716 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
717 # Try to resolve index of the positive label explicitly provided by Ludwig |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
718 pos_label_raw = ( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
719 roc_data.get("positive_label") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
720 or roc_data.get("positive_class") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
721 or label_stats.get("positive_label") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
722 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
723 pos_label_idx = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
724 if pos_label_raw is not None and isinstance(label_list, list): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
725 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
726 pos_label_idx = label_list.index(pos_label_raw) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
727 except ValueError: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
728 pos_label_idx = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
729 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
730 # Fallback: use the second label if available, otherwise the first |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
731 if pos_label_idx is None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
732 if isinstance(label_list, list) and len(label_list) >= 2: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
733 pos_label_idx = 1 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
734 elif isinstance(label_list, list) and label_list: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
735 pos_label_idx = 0 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
736 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
737 if pos_label_raw is None and isinstance(label_list, list) and pos_label_idx is not None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
738 pos_label_raw = label_list[pos_label_idx] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
739 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
740 # Map to friendly label if we have one from metadata/CSV |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
741 pos_label_display = pos_label_raw |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
742 if ( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
743 friendly_labels |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
744 and isinstance(pos_label_idx, int) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
745 and 0 <= pos_label_idx < len(friendly_labels) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
746 ): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
747 pos_label_display = friendly_labels[pos_label_idx] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
748 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
749 pos_label_txt = ( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
750 f"Positive class: {pos_label_display}" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
751 if pos_label_display is not None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
752 else "Positive class: (not available)" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
753 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
754 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
755 title_label = f"ROC Curve{auc_txt}" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
756 if pos_label_display is not None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
757 title_label = f"ROC Curve (Positive Class: {pos_label_display}){auc_txt}" |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
758 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
759 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
760 title=dict(text=title_label, x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
761 xaxis_title="False Positive Rate", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
762 yaxis_title="True Positive Rate", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
763 width=700, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
764 height=600, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
765 margin=dict(t=80, l=80, r=80, b=110), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
766 hovermode="closest", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
767 legend=dict( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
768 x=0.6, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
769 y=0.1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
770 bgcolor="rgba(255,255,255,0.9)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
771 bordercolor="rgba(0,0,0,0.2)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
772 borderwidth=1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
773 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
774 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
775 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
776 fig.update_xaxes(range=[0, 1.0]) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
777 fig.update_yaxes(range=[0, 1.05]) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
778 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
779 fig.add_annotation( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
780 x=0.5, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
781 y=-0.15, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
782 xref="paper", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
783 yref="paper", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
784 showarrow=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
785 text=f"<span style='font-size:12px;color:#555;'>{pos_label_txt}</span>", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
786 xanchor="center", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
787 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
788 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
789 return { |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
790 "title": "ROC Curve", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
791 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
792 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
793 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
794 include_plotlyjs=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
795 config=config, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
796 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
797 } |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
798 except Exception as e: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
799 print(f"Error building ROC plot: {e}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
800 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
801 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
802 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
803 def _build_precision_recall_plot(label_stats: dict, config: dict) -> Optional[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
804 """Build Precision-Recall curve directly from test_statistics.json.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
805 pr_data = label_stats.get("precision_recall_curve") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
806 if not isinstance(pr_data, dict): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
807 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
808 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
809 precisions = pr_data.get("precisions") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
810 recalls = pr_data.get("recalls") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
811 if not precisions or not recalls or len(precisions) != len(recalls): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
812 return None |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
813 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
814 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
815 fig = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
816 fig.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
817 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
818 x=recalls, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
819 y=precisions, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
820 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
821 name="Precision-Recall", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
822 line=dict(color="#d62728", width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
823 hovertemplate="Recall: %{x:.3f}<br>Precision: %{y:.3f}<extra></extra>", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
824 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
825 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
826 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
827 ap_val = ( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
828 label_stats.get("average_precision_macro") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
829 or label_stats.get("average_precision_micro") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
830 or label_stats.get("average_precision_samples") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
831 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
832 ap_txt = f" (AP = {ap_val:.3f})" if isinstance(ap_val, (int, float)) else "" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
833 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
834 fig.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
835 title=dict(text=f"Precision-Recall Curve{ap_txt}", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
836 xaxis_title="Recall", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
837 yaxis_title="Precision", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
838 width=700, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
839 height=600, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
840 margin=dict(t=80, l=80, r=80, b=80), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
841 hovermode="closest", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
842 legend=dict( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
843 x=0.6, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
844 y=0.1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
845 bgcolor="rgba(255,255,255,0.9)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
846 bordercolor="rgba(0,0,0,0.2)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
847 borderwidth=1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
848 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
849 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
850 _style_fig(fig) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
851 fig.update_xaxes(range=[0, 1.0]) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
852 fig.update_yaxes(range=[0, 1.05]) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
853 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
854 return { |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
855 "title": "Precision-Recall Curve", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
856 "html": pio.to_html( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
857 fig, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
858 full_html=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
859 include_plotlyjs=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
860 config=config, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
861 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
862 } |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
863 except Exception as e: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
864 print(f"Error building Precision-Recall plot: {e}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
865 return None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
866 |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
867 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
868 def build_prediction_diagnostics( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
869 predictions_path: str, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
870 label_data_path: Optional[str] = None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
871 split_value: int = 2, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
872 threshold: Optional[float] = None, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
873 ) -> List[Dict[str, str]]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
874 """Generate diagnostic plots from predictions.csv for classification tasks.""" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
875 preds_file = Path(predictions_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
876 if not preds_file.exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
877 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
878 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
879 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
880 df_pred = pd.read_csv(predictions_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
881 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
882 print(f"Warning: Unable to read predictions CSV: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
883 return [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
884 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
885 plots: List[Dict[str, str]] = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
886 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
887 # Identify probability columns |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
888 prob_cols = [ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
889 c for c in df_pred.columns |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
890 if c.startswith("label_probabilities_") and c != "label_probabilities" |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
891 ] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
892 prob_cols_sorted = sorted(prob_cols) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
893 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
894 def _select_positive_prob(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
895 if not prob_cols_sorted: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
896 return None, None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
897 # Prefer a column indicating positive/event/true/1 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
898 preferred_keys = ("event", "true", "positive", "pos", "1") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
899 for col in prob_cols_sorted: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
900 suffix = col.replace("label_probabilities_", "").lower() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
901 if any(k in suffix for k in preferred_keys): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
902 return col, suffix |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
903 if len(prob_cols_sorted) == 2: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
904 col = prob_cols_sorted[1] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
905 return col, col.replace("label_probabilities_", "") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
906 col = prob_cols_sorted[0] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
907 return col, col.replace("label_probabilities_", "") |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
908 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
909 pos_prob_col, pos_label_hint = _select_positive_prob() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
910 pos_prob_series = df_pred[pos_prob_col] if pos_prob_col and pos_prob_col in df_pred else None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
911 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
912 # Confidence series: prefer label_probability, otherwise positive prob, otherwise max prob |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
913 confidence_series = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
914 if "label_probability" in df_pred.columns: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
915 confidence_series = df_pred["label_probability"] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
916 elif pos_prob_series is not None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
917 confidence_series = pos_prob_series |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
918 elif prob_cols_sorted: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
919 confidence_series = df_pred[prob_cols_sorted].max(axis=1) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
920 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
921 # True labels |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
922 def _extract_labels(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
923 candidates = [ |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
924 LABEL_COLUMN_NAME, |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
925 f"{LABEL_COLUMN_NAME}_ground_truth", |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
926 f"{LABEL_COLUMN_NAME}__ground_truth", |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
927 f"{LABEL_COLUMN_NAME}_target", |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
928 f"{LABEL_COLUMN_NAME}__target", |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
929 "label", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
930 "label_true", |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
931 ] |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
932 candidates.extend( |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
933 [ |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
934 col |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
935 for col in df_pred.columns |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
936 if (col.startswith(f"{LABEL_COLUMN_NAME}_") or col.startswith(f"{LABEL_COLUMN_NAME}__")) |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
937 and "probabilities" not in col |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
938 and "predictions" not in col |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
939 ] |
|
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
940 ) |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
941 for col in candidates: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
942 if col in df_pred.columns and col not in prob_cols_sorted: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
943 return df_pred[col] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
944 if label_data_path and Path(label_data_path).exists(): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
945 try: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
946 df_all = pd.read_csv(label_data_path) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
947 if SPLIT_COLUMN_NAME in df_all.columns: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
948 df_all = df_all[df_all[SPLIT_COLUMN_NAME] == split_value].reset_index(drop=True) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
949 if LABEL_COLUMN_NAME in df_all.columns: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
950 return df_all[LABEL_COLUMN_NAME].reset_index(drop=True) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
951 except Exception as exc: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
952 print(f"Warning: Unable to load labels from dataset: {exc}") |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
953 return None |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
954 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
955 labels_series = _extract_labels() |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
956 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
957 # Plot 1: Confidence Histogram |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
958 if confidence_series is not None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
959 fig_conf = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
960 fig_conf.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
961 go.Histogram( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
962 x=confidence_series, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
963 nbinsx=20, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
964 marker=dict(color="#1f77b4", line=dict(color="#ffffff", width=1)), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
965 opacity=0.8, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
966 histnorm="percent", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
967 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
968 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
969 fig_conf.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
970 title=dict(text="Prediction Confidence Distribution", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
971 xaxis_title="Predicted probability (confidence)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
972 yaxis_title="Percentage (%)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
973 bargap=0.05, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
974 width=700, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
975 height=500, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
976 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
977 _style_fig(fig_conf) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
978 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
979 "title": "Prediction Confidence Distribution", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
980 "html": pio.to_html(fig_conf, full_html=False, include_plotlyjs=False), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
981 }) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
982 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
983 # The remaining plots require true labels and a positive-class probability |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
984 if labels_series is None or pos_prob_series is None: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
985 return plots |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
986 |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
987 # Align lengths |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
988 min_len = min(len(labels_series), len(pos_prob_series)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
989 if min_len == 0: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
990 return plots |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
991 y_true_raw = labels_series.iloc[:min_len] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
992 y_score = np.array(pos_prob_series.iloc[:min_len], dtype=float) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
993 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
994 # Determine positive label |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
995 unique_labels = pd.unique(y_true_raw) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
996 unique_labels_list = list(unique_labels) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
997 positive_label = None |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
998 if pos_label_hint and str(pos_label_hint) in [str(u) for u in unique_labels_list]: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
999 positive_label = pos_label_hint |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1000 elif len(unique_labels_list) == 2: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1001 positive_label = unique_labels_list[1] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1002 else: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1003 positive_label = unique_labels_list[0] |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
1004 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1005 y_true = (y_true_raw == positive_label).astype(int).values |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
1006 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1007 # Plot 2: Calibration Curve |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1008 bins = np.linspace(0.0, 1.0, 11) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1009 bin_ids = np.digitize(y_score, bins, right=True) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1010 bin_centers = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1011 frac_positives = [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1012 for b in range(1, len(bins)): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1013 mask = bin_ids == b |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1014 if not np.any(mask): |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1015 continue |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1016 bin_centers.append(y_score[mask].mean()) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1017 frac_positives.append(y_true[mask].mean()) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1018 if bin_centers and frac_positives: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1019 fig_cal = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1020 fig_cal.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1021 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1022 x=bin_centers, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1023 y=frac_positives, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1024 mode="lines+markers", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1025 name="Calibration", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1026 line=dict(color="#2ca02c", width=4), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1027 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1028 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1029 fig_cal.add_trace( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1030 go.Scatter( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1031 x=[0, 1], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1032 y=[0, 1], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1033 mode="lines", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1034 name="Perfect Calibration", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1035 line=dict(color="gray", width=2, dash="dash"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1036 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1037 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1038 fig_cal.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1039 title=dict(text="Calibration Curve", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1040 xaxis_title="Predicted probability", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1041 yaxis_title="Observed frequency", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1042 width=700, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1043 height=500, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1044 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1045 _style_fig(fig_cal) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1046 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1047 "title": "Calibration Curve (Predicted Probability vs Observed Frequency)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1048 "html": pio.to_html(fig_cal, full_html=False, include_plotlyjs=False), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1049 }) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
1050 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1051 # Plot 3: Threshold vs Metrics |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1052 thresholds = np.linspace(0.0, 1.0, 21) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1053 accs, f1s, sens, specs = [], [], [], [] |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1054 for t in thresholds: |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1055 y_pred = (y_score >= t).astype(int) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1056 tp = np.sum((y_true == 1) & (y_pred == 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1057 tn = np.sum((y_true == 0) & (y_pred == 0)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1058 fp = np.sum((y_true == 0) & (y_pred == 1)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1059 fn = np.sum((y_true == 1) & (y_pred == 0)) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1060 acc = (tp + tn) / max(len(y_true), 1) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1061 prec = tp / max(tp + fp, 1e-9) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1062 rec = tp / max(tp + fn, 1e-9) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1063 f1 = 0 if (prec + rec) == 0 else 2 * prec * rec / (prec + rec) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1064 sensitivity = rec |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1065 specificity = tn / max(tn + fp, 1e-9) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1066 accs.append(acc) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1067 f1s.append(f1) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1068 sens.append(sensitivity) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1069 specs.append(specificity) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
1070 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1071 fig_thresh = go.Figure() |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1072 fig_thresh.add_trace(go.Scatter(x=thresholds, y=accs, mode="lines", name="Accuracy", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1073 fig_thresh.add_trace(go.Scatter(x=thresholds, y=f1s, mode="lines", name="F1", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1074 fig_thresh.add_trace(go.Scatter(x=thresholds, y=sens, mode="lines", name="Sensitivity", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1075 fig_thresh.add_trace(go.Scatter(x=thresholds, y=specs, mode="lines", name="Specificity", line=dict(width=4))) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1076 fig_thresh.update_layout( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1077 title=dict(text="Threshold Sweep: Accuracy, F1, Sensitivity, Specificity", x=0.5), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1078 xaxis_title="Decision threshold", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1079 yaxis_title="Metric value", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1080 width=700, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1081 height=500, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1082 legend=dict( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1083 x=0.7, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1084 y=0.2, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1085 bgcolor="rgba(255,255,255,0.9)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1086 bordercolor="rgba(0,0,0,0.2)", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1087 borderwidth=1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1088 ), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1089 shapes=[ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1090 dict( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1091 type="line", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1092 x0=threshold, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1093 x1=threshold, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1094 y0=0, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1095 y1=1, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1096 xref="x", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1097 yref="paper", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1098 line=dict(color="#d62728", width=2, dash="dash"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1099 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1100 ] if isinstance(threshold, (int, float)) else [], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1101 annotations=[ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1102 dict( |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1103 x=threshold, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1104 y=1.02, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1105 xref="x", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1106 yref="paper", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1107 showarrow=False, |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1108 text=f"Threshold = {threshold:.2f}", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1109 font=dict(size=11, color="#d62728"), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1110 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1111 ] if isinstance(threshold, (int, float)) else [], |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1112 ) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1113 _style_fig(fig_thresh) |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1114 plots.append({ |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1115 "title": "Threshold Sweep: Accuracy, F1, Sensitivity, Specificity", |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1116 "html": pio.to_html(fig_thresh, full_html=False, include_plotlyjs=False), |
|
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1117 }) |
|
11
c5150cceab47
planemo upload for repository https://github.com/goeckslab/gleam.git commit 0fe927b618cd4dfc87af7baaa827034cc6813225
goeckslab
parents:
8
diff
changeset
|
1118 |
|
15
d17e3a1b8659
planemo upload for repository https://github.com/goeckslab/gleam.git commit bc50fef8acb44aca15d0a1746e6c0c967da5bb17
goeckslab
parents:
11
diff
changeset
|
1119 return plots |
