Gaussian log likelihood metric

From wenmin-wu/ds-skills · View interactive version

Gaussian log likelihood metric is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Evaluate probabilistic forecasts using normalized Gaussian log-likelihood relative to naive and oracle baselines, scoring both mean accuracy and uncertainty calibration

How to use this skill

Skill file

Gaussian Log-Likelihood Metric

Overview

For regression tasks requiring uncertainty estimates, score predictions using Gaussian log-likelihood normalized between a naive baseline and an oracle. The metric rewards both accurate mean predictions AND well-calibrated uncertainty (sigma). Overconfident predictions (small sigma, wrong mean) are penalized heavily. Score ranges from 0 (= naive) to 1 (= oracle).

Quick Start

import numpy as np
from scipy.stats import norm

def gaussian_log_likelihood_score(y_true, y_pred, sigma_pred,
                                   naive_mean, naive_sigma, sigma_true):
    """Normalized Gaussian log-likelihood metric.
    
    Args:
        y_true: ground truth values (n_samples, n_targets)
        y_pred: predicted means (n_samples, n_targets)
        sigma_pred: predicted uncertainties (n_samples, n_targets)
        naive_mean: baseline mean prediction (n_targets,)
        naive_sigma: baseline uncertainty (n_targets,)
        sigma_true: oracle uncertainty (n_samples, n_targets)
    Returns:
        score in [0, 1] where 1 is perfect
    """
    sigma_pred = np.clip(sigma_pred, 1e-15, None)
    
    gll_pred = np.sum(norm.logpdf(y_true, loc=y_pred, scale=sigma_pred))
    gll_oracle = np.sum(norm.logpdf(y_true, loc=y_true, scale=sigma_true))
    gll_naive = np.sum(norm.logpdf(y_true, loc=naive_mean, scale=naive_sigma))
    
    score = (gll_pred - gll_naive) / (gll_oracle - gll_naive)
    return float(np.clip(score, 0.0, 1.0))

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.