@@ -55,7 +55,7 @@ def __init__(
5555 for metric in metrics :
5656 self .results .append (test (metric = metric , threshold = threshold ).run (** run_kwargs ).to_dict ())
5757
58- def to_dataframe (self ):
58+ def to_dataframe (self , summary : Optional [ bool ] = False ):
5959 """
6060 Converts the test results to a pandas DataFrame.
6161
@@ -68,23 +68,56 @@ def to_dataframe(self):
6868 except (ImportError , ModuleNotFoundError ) as e :
6969 raise GiskardImportError (["pandas" ]) from e
7070
71+ df = pd .DataFrame (self .results )
72+
73+ for col in ["metric_value" , "prediction_time" , "prediction_fail_rate" ]:
74+ col_name = f"Best({ col } )"
75+ # Create a new column 'Best' and set it to False by default
76+ df [col_name ] = ""
77+
7178 # columns reordering
72- df = pd . DataFrame ( self . results ) [
79+ df = df [
7380 [
7481 "dataloader" ,
7582 "model" ,
7683 "test" ,
7784 "metric" ,
7885 "metric_value" ,
79- "threshold" ,
80- "passed" ,
86+ "Best(metric_value)" ,
8187 "prediction_time" ,
88+ "Best(prediction_time)" ,
8289 "prediction_fail_rate" ,
90+ "Best(prediction_fail_rate)" ,
8391 ]
8492 ].rename (columns = {"dataloader" : "criteria" })
93+
94+ df = df .sort_values (["criteria" , "model" ], ignore_index = True )
95+
96+ # Add a column for grouping n models
97+ df ["group" ] = df .index // df ["model" ].nunique ()
98+
99+ for col in ["metric_value" , "prediction_time" , "prediction_fail_rate" ]:
100+ # Group by the 'group' column and find the index of the minimum value in column col for each group
101+ min_col = df .groupby ("group" )[col ].idxmin ()
102+ col_name = f"Best({ col } )"
103+ # Set the 'Best' column to True for the rows corresponding to the minimum indices
104+ df .loc [min_col , col_name ] = "✓"
105+
106+ if summary :
107+ # columns filtering
108+ df = df [
109+ [
110+ "criteria" ,
111+ "model" ,
112+ "Best(metric_value)" ,
113+ "Best(prediction_time)" ,
114+ "Best(prediction_fail_rate)" ,
115+ ]
116+ ]
117+
85118 return df .sort_values (["criteria" , "model" ], ignore_index = True )
86119
87- def to_markdown (self , filename : Optional [str ] = None ):
120+ def to_markdown (self , summary : Optional [ bool ] = False , filename : Optional [str ] = None ):
88121 """
89122 Writes the test results to a markdown file.
90123
@@ -101,7 +134,8 @@ def to_markdown(self, filename: Optional[str] = None):
101134 current_time = str (datetime .now ()).replace (" " , "-" )
102135 filename = f"report_{ current_time } .md"
103136
104- df = self .to_dataframe ()
137+ df = self .to_dataframe (summary = summary )
138+
105139 df .to_markdown (filename )
106140
107141 def to_json (self , filename : Optional [str ] = None ):
0 commit comments