Epoch prediction averaging

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

Epoch prediction averaging is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Collect test predictions each epoch via callback and combine with exponentially increasing weights favoring later epochs

How to use this skill

Skill file

Overview

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.

Quick Start

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)

Workflow

  1. Create a callback that runs model.predict on test data at each epoch end
  2. Store predictions in a list indexed by epoch
  3. After training completes, define exponential weights: [2^0, 2^1, ..., 2^(n-1)]
  4. Compute weighted average across all epoch predictions
  5. Use the averaged predictions for submission

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.