def _extract_selection_performance_per_metric(selection_state: HPSelectionState, metric: Metric, split_count): performance = {"setting": [], **{f"split {i + 1}": [] for i in range(split_count)}} for hp_setting, hp_item_list in selection_state.hp_items.items(): performance['setting'].append(str(hp_setting)) for index, hp_item in enumerate(hp_item_list): performance[f'split {index + 1}'].append(HPHTMLBuilder._print_metric(hp_item.performance, metric)) s = io.StringIO() pd.DataFrame(performance).rename(columns={"setting": 'Hyperparameter settings (preprocessing, encoding, ML method)'}).to_csv(s, sep="\t", index=False) return Util.get_table_string_from_csv_string(s.getvalue(), separator="\t")
def _extract_assessment_performances_per_metric(state: TrainMLModelState, assessment_state: HPAssessmentState, label: str) -> str: performance_metric = {"setting": [], **{metric.name.lower(): [] for metric in state.metrics}} for hp_setting, hp_item in assessment_state.label_states[label].assessment_items.items(): performance_metric['setting'].append(str(hp_setting)) for metric in sorted(state.metrics, key=lambda metric: metric.name.lower()): performance_metric[metric.name.lower()].append(HPHTMLBuilder._print_metric(hp_item.performance, metric)) s = io.StringIO() pd.DataFrame(performance_metric).rename(columns={"setting": 'Hyperparameter settings (preprocessing, encoding, ML method)'})\ .to_csv(s, sep="\t", index=False) return Util.get_table_string_from_csv_string(s.getvalue(), separator="\t")