skills/cv/epoch-prediction-averaging/SKILL.md
Collect test predictions each epoch via callback and combine with exponentially increasing weights favoring later epochs
npx skillsauth add wenmin-wu/ds-skills cv-epoch-prediction-averagingInstall 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.
Instead of using only the final-epoch model for inference, collect test predictions at the end of every epoch and combine them with exponentially increasing weights. Later epochs get more weight because the model improves over training. This acts as a free ensemble across training checkpoints without saving multiple model files.
import numpy as np
from keras.callbacks import Callback
class PredictionCheckpoint(Callback):
def __init__(self, test_generator, test_len):
self.test_generator = test_generator
self.test_len = test_len
self.test_predictions = []
def on_epoch_end(self, epoch, logs=None):
preds = self.model.predict(self.test_generator)[:self.test_len]
self.test_predictions.append(preds)
# After training
weights = [2 ** i for i in range(len(cb.test_predictions))] # 1, 2, 4, 8, ...
final_preds = np.average(cb.test_predictions, axis=0, weights=weights)
model.predict on test data at each epoch end[2^0, 2^1, ..., 2^(n-1)]n_epochs * n_samples * n_classes memory. For large test sets, keep only the last K epochs.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