Skip to content

tensordfmetricwrapper

tensordfmetricwrapper

Module for TensorDfMetricWrapper

Classes

TensorDfMetricWrapper

TensorDfMetricWrapper(
    key, df_metric_list, parquet_filename
)

Bases: TensorMetric

Wrapper for TensorMetric to include dataframe metrics

Source code in niceml/mlcomponents/resultanalyzers/tensors/tensordfmetricwrapper.py
def __init__(self, key: str, df_metric_list: List[DfMetric], parquet_filename: str):
    super().__init__(key=key)
    self.df_metric_list = df_metric_list

    if "." in parquet_filename:
        module_name, class_name, filename = parquet_filename.rsplit(".", 2)
        module_name_object = importlib.import_module(module_name)
        parquet_filename = getattr(
            getattr(module_name_object, class_name), filename
        ).value
    if ".parq" not in parquet_filename:
        parquet_filename = f"{parquet_filename}.parq"

    self.parquet_filename = parquet_filename
Functions
analyse_datapoint
analyse_datapoint(
    data_key,
    data_predicted,
    data_loaded,
    additional_data,
    **kwargs
)

Not required due to dataframe analysis

Source code in niceml/mlcomponents/resultanalyzers/tensors/tensordfmetricwrapper.py
def analyse_datapoint(
    self,
    data_key: str,
    data_predicted,
    data_loaded,
    additional_data: dict,
    **kwargs,
) -> Optional[Any]:
    """Not required due to dataframe analysis"""
get_final_metric
get_final_metric()

Reads the parquet file and runs the dataframe metrics on it

Source code in niceml/mlcomponents/resultanalyzers/tensors/tensordfmetricwrapper.py
def get_final_metric(self) -> Optional[dict]:
    """Reads the parquet file and runs the dataframe metrics on it"""
    cur_df: pd.DataFrame = self.exp_context.read_parquet(
        join(
            ExperimentFilenames.ANALYSIS_FOLDER,
            self.parquet_filename.format(subset=self.dataset_name),
        )
    )

    outdict = {}
    for df_metric in self.df_metric_list:
        cur_out_dict = df_metric(cur_df, self.exp_context, self.dataset_name)
        if cur_out_dict is not None:
            outdict.update(cur_out_dict)
    return outdict