Classification Score Visualization

The output of sklearn.metrics.classification_report is a string by default, but it can be set as a dictionary with the kwarg output_dict=True. As @marduk pointed out, that is rendered nicely with a st.dataframe().

image

import streamlit as st
from sklearn.metrics import classification_report

y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]

target_names = ["class 0", "class 1", "class 2"]

st.dataframe(
    classification_report(y_true, y_pred, target_names=target_names, output_dict=True)
)

Edit: I just realized the output is flipped, but that can be fixed transposing the dataframe.

image

import streamlit as st
from sklearn.metrics import classification_report
import pandas as pd

y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ["class 0", "class 1", "class 2"]

st.dataframe(
    pd.DataFrame(
        classification_report(y_true, y_pred, target_names=target_names, output_dict=True)
    ).transpose()
)
2 Likes