Skip to content

Commit

Permalink
fix standalone print bug when cols too many
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing committed Nov 18, 2022
1 parent 4c9e8ba commit ec96916
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions client/starwhale/core/eval/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,25 @@ def _print_labels() -> None:
console.rule(f"[bold green]{report['kind'].upper()} Label Metrics Report")
console.print(table)

def _print_confusion_matrix() -> None:
def _print_confusion_matrix(max_cols: int = 30) -> None:
cm = report.get("confusion_matrix", {})
if not cm:
return

btable = Table(box=box.SIMPLE)
btable = Table(box=box.ROUNDED)
btable.add_column("", style="cyan")
for n in sort_label_names:
for idx, n in enumerate(sort_label_names):
if idx > max_cols:
btable.add_column('...')
break
btable.add_column(n)
for idx, bl in enumerate(cm.get("binarylabel", [])):
btable.add_row(
sort_label_names[idx],
*[f"{float(bl[i]):.4f}" for i in bl if i != "id"],
*[f"{float(bl[i]):.4f}" for idx, i in enumerate(bl) if i != "id" and idx < max_cols],
)

console.rule(f"[bold green]{report['kind'].upper()} Confusion Matrix")
console.print(btable)
console.print(btable, overflow="ignore", crop=True, new_line_start=False)

_print_labels()
_print_confusion_matrix()
Expand Down

0 comments on commit ec96916

Please sign in to comment.