skills/tabular/group-mean-log-mae-metric/SKILL.md
Custom evaluation metric that computes log of per-group MAE then averages, penalizing uniformly bad groups.
npx skillsauth add wenmin-wu/ds-skills tabular-group-mean-log-mae-metricInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When predictions span multiple types or groups with different scales, a global MAE favors high-volume groups. Group Mean Log MAE computes MAE per group, takes the log of each, then averages. The log transform penalizes groups where MAE is large relative to its own scale, ensuring the model performs well across all groups — not just the largest.
import numpy as np
def group_mean_log_mae(y_true, y_pred, groups, floor=1e-9):
"""Compute mean of log(MAE) across groups.
Args:
y_true: array of true values
y_pred: array of predictions
groups: array of group labels (same length)
floor: minimum MAE to avoid log(0)
"""
errors = np.abs(y_true - y_pred)
unique_groups = np.unique(groups)
log_maes = []
for g in unique_groups:
mask = groups == g
mae = errors[mask].mean()
log_maes.append(np.log(max(mae, floor)))
return np.mean(log_maes)
# LightGBM custom metric
def lgb_group_metric(y_pred, data, groups):
y_true = data.get_label()
score = group_mean_log_mae(y_true, y_pred, groups)
return 'group_log_mae', score, False # lower is better
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF