annotate-relevance / analysis.py
Orion Weller
hopefilly
bf8e6b0
raw
history blame
1.34 kB
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