syndat.rct.metrics_rct
- syndat.rct.metrics_rct.compute_categorical_error_metrics(rp0, dt, mode='Reconstructed', average='weighted', strat_vars=None, static=False, per_time_mean=False, per_variable_mean=False)
Computes classification metrics for long-format categorical variables. Returns a dict with full metrics, per-time mean, per-variable mean, and overall mean.
- Parameters:
rp0 (
dict) – Dictionary with key ‘long_cat’ and/or ‘long_bin’ with list of categorical variable names.dt (
DataFrame) – Main DataFrame containing data for “Observed” and mode.mode (
str) – String, usually “Reconstructed”, used for filtering TYPE.average (
str) – what to calculate the average. Macro micro or weighted.strat_vars (
Optional[List[str]]) – List of column names to stratify by (e.g., [‘DRUG’]).static (
bool) – If True, metrics for static variables will be calculated.per_time_mean (
bool) – If True, returns mean error per time point (averaged across variables).per_variable_mean (
bool) – If True, returns mean error per variable (averaged across time).
- Return type:
Dict[str,DataFrame]- Returns:
Dict of dataframes with keys: - ‘full’: full stratified error metrics - ‘per_time’: (optional) mean per time point - ‘per_variable’: (optional) mean per variable - ‘overall’: overall mean values
- syndat.rct.metrics_rct.compute_continuous_error_metrics(rp0, dt, mode='Reconstructed', strat_vars=None, static=False, per_time_mean=False, per_variable_mean=False, epsilon=1e-08)
Computes MAE, RMSE, and MAPE stratified by variables like DRUG, per TIME and Variable.
- Parameters:
rp0 (
dict) – Dictionary with key ‘long_cont’ containing a list of continuous variable names.dt (
DataFrame) – Main DataFrame containing data for “Observed” and mode.mode (
str) – String, usually “Reconstructed”, used for filtering TYPE.strat_vars (
Optional[List[str]]) – List of column names to stratify by (e.g., [‘DRUG’]).static (
bool) – If True, metrics for static variables will be calculated.per_time_mean (
bool) – If True, returns mean error per time point (averaged across variables).per_variable_mean (
bool) – If True, returns mean error per variable (averaged across time).epsilon (
float) – Small value added to denominator for MAPE to avoid division by zero.
- Return type:
DataFrame- Returns:
Dict of dataframes with keys: - ‘full’: full stratified error metrics - ‘per_time’: (optional) mean per time point - ‘per_variable’: (optional) mean per variable - ‘overall’: overall mean values