Spaces:
Sleeping
Sleeping
File size: 1,341 Bytes
bf8e6b0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.figure_factory as ff
def results_to_df(results: dict, metric_name: str):
metric_scores = []
for topic, results_dict in results.items():
for metric_name_cur, metric_value in results_dict.items():
if metric_name == metric_name_cur:
metric_scores.append(metric_value)
return pd.DataFrame({metric_name: metric_scores})
def create_boxplot_1df(results: dict, metric_name: str):
df = results_to_df(results, metric_name)
fig = px.box(df, y=metric_name)
return fig
def create_boxplot_2df(results1, results2, metric_name):
df1 = results_to_df(results1, metric_name)
df2 = results_to_df(results2, metric_name)
df2["Run"] = "Run 2"
df1["Run"] = "Run 1"
df = pd.concat([df1, df2])
# Create distplot with custom bin_size
fig = px.histogram(df, x=metric_name, color="Run", marginal="box", hover_data=df.columns)
return fig
def create_boxplot_diff(results1, results2, metric_name):
df1 = results_to_df(results1, metric_name)
df2 = results_to_df(results2, metric_name)
diff = df1[metric_name] - df2[metric_name]
x_axis = f"Difference in {metric_name} from 1 to 2"
fig = px.histogram(pd.DataFrame({x_axis: diff}), x=x_axis, marginal="box")
return fig |