Browse Source

add to trials to csv function

ogert 2 years ago
parent
commit
92667b4138
1 changed files with 21 additions and 0 deletions
  1. 21 0
      cdplib/hyperopt/HyperoptPipelineSelector.py

+ 21 - 0
cdplib/hyperopt/HyperoptPipelineSelector.py

@@ -457,6 +457,27 @@ class HyperoptPipelineSelector(PipelineSelector):
 
             self._logger.log_and_raise_error(err)
 
+    def trials_to_csv(self, path: str = None) -> None:
+        """
+        Saves an csv file with pipeline names, scores,
+        parameters, and timestamps.
+        """
+        try:
+            results = [trial["result"] for trial in self._trials.trials]
+
+            space_elements = [self._get_space_element_from_trial(trial)
+                              for trial in self._trials.trials]
+
+            pd.DataFrame([{**result, **space_element}
+                          for result, space_element in
+                          zip(results, space_elements)]).to_csv(path)
+
+        except Exception as e:
+            err = ("Failed to write trials to csv. "
+                   "Exit with error: {}".format(e))
+
+            self._logger.log_and_raise_error(err)
+
 
 if __name__ == '__main__':