Ensembling — average models, then predict
Background
A post-training way to fight overfitting: train several models (different seeds, folds, or architectures) and average their predicted probabilities before deciding. Averaging cancels each model's idiosyncratic errors, reducing variance:
Problem statement
Implement ensemble_predict(probs) that averages the per-class probabilities across models and returns the predicted class per example.
Input
probs— array-like of shape(M, n, K):Mmodels,nexamples,Kclasses.probs[m, i]is modelm's probability vector for examplei.
Output
Returns an np.ndarray of n integer class labels — the argmax of the model-averaged probabilities.
Examples
Example 1
Input: probs = [[[0.9, 0.1], [0.2, 0.8]],
[[0.4, 0.6], [0.3, 0.7]]]
Output: [0 1]
Explanation: averages are , whose argmaxes are and .
Example 2 — the ensemble overturns a confident outlier
Input: probs = [[[0.1, 0.9]], [[0.55, 0.45]], [[0.6, 0.4]]]
Output: [0]
Explanation: average ? No — → class 1. (See test for the exact case.)
Constraints
- Average over the model axis (axis 0), giving shape
(n, K). - Predict with
argmaxover the class axis. - Return an integer
np.ndarrayof lengthn.
Notes
- Ensembling trades extra inference compute for lower variance — it polishes predictions but doesn't replace good data and regularization.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •example: two models, two examples
- •reference: mild majority overturns one confident model
- •sample: three-class agreement