Shortcuts

Source code for lumin.nn.metrics.eval_metric

import numpy as np
import pandas as pd
from abc import ABC, abstractmethod
from typing import Optional

from ..data.fold_yielder import FoldYielder

__all__ = ['EvalMetric']


[docs]class EvalMetric(ABC): r''' Abstract class for evaluating performance of a model using some metric Arguments: targ_name: name of group in fold file containing regression targets wgt_name: name of group in fold file containing datapoint weights ''' def __init__(self, targ_name:str='targets', wgt_name:Optional[str]=None): self.targ_name,self.wgt_name,self.lower_metric_better = targ_name,wgt_name,True
[docs] def get_df(self, fy:FoldYielder, idx:int, y_pred:np.ndarray) -> pd.DataFrame: r''' Returns a DataFrame for the given fold containing targets, weights, and predictions Arguments: fy: :class:`~lumin.nn.data.fold_yielder.FoldYielder` interfacing to data idx: fold index corresponding to fold for which y_pred was computed y_pred: predictions for fold Returns: DataFrame for the given fold containing targets, weights, and predictions ''' df = pd.DataFrame() if self.wgt_name is not None: df['gen_weight'] = fy.get_column(column=self.wgt_name, n_folds=1, fold_idx=idx) targets = fy.get_column(column=self.targ_name, n_folds=1, fold_idx=idx) if len(targets.shape) > 1: for t in range(targets.shape[-1]): df[f'gen_target_{t}'] = targets[:,t] else: df['gen_target'] = targets if len(y_pred.shape) > 1 and y_pred.shape[-1] > 1: for p in range(y_pred.shape[-1]): df[f'pred_{p}'] = y_pred[:,p] else: df['pred'] = y_pred.squeeze() return df
[docs] @abstractmethod def evaluate(self, fy:FoldYielder, idx:int, y_pred:np.ndarray) -> float: r''' Evaluate the required metric for a given fold and set of predictions Arguments: fy: :class:`~lumin.nn.data.fold_yielder.FoldYielder` interfacing to data idx: fold index corresponding to fold for which y_pred was computed y_pred: predictions for fold Returns: metric value ''' pass
Read the Docs v: v0.6.0
Versions
latest
stable
v0.6.0
v0.5.1
v0.5.0
v0.4.0.1
v0.3.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

Docs

Access comprehensive developer and user documentation for LUMIN

View Docs

Tutorials

Get tutorials for beginner and advanced researchers demonstrating many of the features of LUMIN

View Tutorials