[docs]classFeatureReport(EncodingReport):""" Base class for reports that plot something about the reshaped feature values of any dataset. """def__init__(self,dataset:Dataset=None,result_path:Path=None,color_grouping_label:str=None,row_grouping_label=None,column_grouping_label=None,name:str=None,number_of_processes:int=1):super().__init__(dataset=dataset,result_path=result_path,name=name,number_of_processes=number_of_processes)self.x="feature"self.color=color_grouping_labelself.facet_row=row_grouping_labelself.facet_column=column_grouping_labeldef_generate_report_result(self)->ReportResult:PathBuilder.build(self.result_path)data_long_format=DataReshaper.reshape(self.dataset,self.dataset.get_label_names())table_result=self._write_results_table(data_long_format)report_output=self._safe_plot(data_long_format=data_long_format)output_tables=[table_result]ifreport_outputisNone:output_figures=Noneelifisinstance(report_output,tuple):output_figures=report_output[0]ifisinstance(report_output[0],list)else[report_output[0]]output_tables=report_output[1]else:output_figures=report_outputifisinstance(report_output,list)else[report_output]returnReportResult(name=self.name,output_figures=output_figures,output_tables=output_tables)def_write_results_table(self,data)->ReportOutput:table_path=self.result_path/f"feature_values.csv"data.to_csv(table_path,index=False)returnReportOutput(table_path,"feature values")
[docs]defcheck_prerequisites(self):location=self.__class__.__name__run_report=Trueifself.dataset.encoded_dataisNoneorself.dataset.encoded_data.examplesisNone:warnings.warn(f"{location}: this report can only be created for an encoded dataset. {location} report will not be created.")run_report=Falseeliflen(self.dataset.encoded_data.examples.shape)!=2:warnings.warn(f"{location}: this report can only be created for a 2-dimensional encoded dataset. {location} report will not be created.")run_report=Falseelse:legal_labels=list(self.dataset.get_label_names())labels=[self.color,self.facet_row,self.facet_column]forlabel_paraminlabels:iflabel_paramisnotNone:iflabel_paramnotinlegal_labels:warnings.warn(f"{location}: undefined label '{label_param}'. Legal options are: {legal_labels}. {location} report will not be created.")run_report=Falsereturnrun_report