kaggle-optimal-blending
Skill5 starsChanged 35 days agoMITView on GitHub
Optimal blending strategy for Kaggle competitions: 80/20 rule (re-ranking vs raw). Use when: (1) Re-ranking gives unexpected results, (2) Simple average blending underperforms, (3) Single model dominates ensemble. Avoids the trap of 100% re-ranking or equal-weight ensembles. **UPDATED 2026-06-14**: Added asymmetric-blending principle (30/70 rule) for general tabular ensembles. When one model family dominates (e.g., CatBoost in Spaceship Titanic 0.8124 OOF acc), weight it higher than other families. Validated: 30% Silver + 70% Top-5 = 0.8132 OOF (best on SST V3).
In this repository63 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-validation-kaggleSkill
- agent-nurture-frameworkSkill
- agent-session-memory-protocolSkill
- arxiv-paper-searchSkill
- autogluon-firstSkill
- autogluon-preset-strategySkill
- autogluon-timeseries-strategySkill
- catboost-first-tabularSkill
- claudeceptionSkill
- code-competition-artifact-pipelineSkill
- competition-orchestration-multimodelSkill
- context-engineeringSkill
- controlled-submission-experimentSkill
- cross-competition-feature-transferSkill
- cv-lb-gap-acknowledgmentSkill
- domain-knowledge-constraints-trapSkill
- ensemble-model-correlation-trapSkill
- feature-engineering-saturation-detectionSkill
- gpu-readiness-assessmentSkill
- gsd-loop-engineeringSkill
- kaggle-cognitive-cost-optimizationSkill
- kaggle-competition-best-practicesSkill
- kaggle-competition-type-strategySkill
- kaggle-data-format-firstSkill
- kaggle-discussion-searchSkill
- kaggle-experiment-sopSkill
- kaggle-oof-lb-validation-protocolSkill
- kaggle-submission-format-by-metricSkill
- kaggle-top-performer-replicationSkill
- knowledge-crystallization-feedback-loopSkill
- ladder-drift-and-meta-aware-regressionSkill
- learned-value-beats-heuristic-augmentationSkill
- llm-competition-pipelineSkill
- mcts-pipeline-searchSkill
- mem0-dynamic-graph-memorySkill
- memory-hierarchy-managementSkill
- ml-sweet-spot-principleSkill
- model-ensemble-negative-weight-effectSkill
- multi-agent-rolesSkill
- multi-level-aggregation-overfittingSkill
- okf-visualize-knowledgeSkill
- onnx-minimal-network-designSkill
- per-category-modeling-backfireSkill
- progressive-verification-debuggingSkill
- ptcg-2ply-bounded-searchSkill
- ptcg-bc-large-model-submissionSkill
- retail-eda-frameworkSkill
- rmsle-zero-threshold-asymmetrySkill
- runtime-reflexionSkill
- sc-tir-mathematical-reasoningSkill
- self-evolving-skillsSkill
- skill-governance-and-automationSkill
- spatiotemporal-graph-feature-engineeringSkill
- store-sales-darts-chronos-blendSkill
- tabular-polynomial-features-breakthroughSkill
- three-layer-wisdom-extractionSkill
- time-series-walk-forward-validationSkill
- trueskill-simulation-competition-strategySkill
- ts-day-specific-forecastingSkill
- The first 60 shown.
The file
Files
Kaggle Optimal Blending: The 80/20 Rule
Problem
Re-ranking (k-reciprocal, Jaccard, etc.) is powerful but using 100% re-ranked results can lose valuable signal diversity. Equal-weight blending often underperforms.
Context / Trigger Conditions
Use when:
- Implementing post-processing for Re-ID, retrieval, or recommendation tasks
- Re-ranking alone doesn't give expected boost
- Ensemble of multiple models shows little improvement
- Kaggle score plateaus despite strong individual models
Solution
The 80/20 Optimal Blending Rule
Key insight from 0.938 mAP solution (Jaguar Re-ID):
blend_raw_ratio = 0.20 # 20% raw, 80% re-ranked
final_similarity = (
(1 - blend_raw_ratio) * rerank_score +
blend_raw_ratio * raw_score
)Why 80/20?
- 80% re-ranking: Captures neighborhood structure, removes false positives
- 20% raw: Preserves genuine long-range similarities, maintains diversity
- This ratio emerged as optimal through experimentation (0.938 mAP)
Implementation
import numpy as np
def optimal_blend(similarity_matrix, reranked_matrix, raw_ratio=0.20):
"""
Blend re-ranked and raw similarity matrices
Args:
similarity_matrix: Original NxM similarity matrix
reranked_matrix: Re-ranked version (k-reciprocal, etc.)
raw_ratio: Weight for raw score (default 0.20)
Returns:
Blended similarity matrix
"""
return (1 - raw_ratio) * reranked_matrix + raw_ratio * similarity_matrixRe-Ranking Parameters (Optimized for 0.938 mAP)
# k-Reciprocal Re-ranking parameters
k1 = 20 # First k for reciprocal neighbors
k2 = 6 # Second k for final re-ranking
lambda_param = 0.2 # Jaccard weightComplete Post-Processing Pipeline
def post_process_for_reid(query_features, gallery_features):
"""
Complete post-processing: TTA + QE + Re-ranking + Optimal Blend
"""
# 1. TTA (Test Time Augmentation)
# query_features = (f_original + f_flipped) / 2
# 2. Query Expansion (optional)
# Expand with top-k gallery samples
qe_top_k = 3
# 3. Compute raw similarities
raw_sim = cosine_similarity(query_features, gallery_features)
# 4. Re-ranking (k-reciprocal)
reranked_sim = k_reciprocal_reranking(
raw_sim,
k1=k1,
k2=k2,
lambda_param=lambda_param
)
# 5. Optimal blending (THE KEY!)
final_sim = optimal_blend(
raw_sim,
reranked_sim,
raw_ratio=0.20 # Don't use 0.0 or 0.5!
)
return final_simVerification
Test the blend ratio:
# Test different ratios
for ratio in [0.0, 0.10, 0.15, 0.20, 0.25, 0.30]:
blended = optimal_blend(raw_sim, reranked_sim, raw_ratio=ratio)
score = evaluate(blended, val_labels)
print(f"Ratio {ratio}: {score:.4f}")Expected pattern:
- 0.0 (100% re-rank): Good but may over-prune
- 0.10: Better
- 0.20: Optimal ← Use this!
- 0.25: Slight decline
- 0.50: Significant decline (too much raw)
Example
Jaguar Re-ID Competition:
# Without optimal blending
# Re-ranking only: 0.92 mAP
# Raw only: 0.85 mAP
# With optimal blending (80/20)
final_score = 0.8 * reranked + 0.2 * raw
# Result: 0.938 mAP (+1.8% over re-ranking alone)H-Blend Strategy (0.944 mAP solution):
# Single strong model should dominate
weights = {
'model_0.944': 0.95, # Dominant!
'model_0.938': 0.02,
'model_0.937': 0.02,
'model_0.930': 0.01,
}This validates the "ensemble-model-correlation-trap" skill.
Notes
When to Use 80/20
✅ Person/Animal Re-ID tasks ✅ Image retrieval with re-ranking ✅ Recommendation systems with neighborhood methods ✅ Any metric learning task with post-processing
When to Adjust the Ratio
- Very clean data: Try 0.15 (more re-ranking)
- Noisy data: Try 0.25-0.30 (more raw signal)
- High threshold requirements: Try 0.10
Common Mistakes
❌ Using 100% re-ranking (loses diversity) ❌ Using 50/50 blend (loses re-ranking benefit) ❌ Equal-weight ensembles (use 95/5 for strong/weak) ❌ Tuning ratio on test set (use validation only!)
Related Skills
ensemble-model-correlation-trap: Why strong models should dominatek-reciprocal-reranking: Implementation detailseva02-reid-backbone: Produces strong features for blending
References
- Kaggle Jaguar Re-ID: sanidhyavijay24 (0.938 mAP)
- Kaggle Jaguar Re-ID: nina2025 H-Blend (0.944 mAP)
- k-Reciprocal Re-ranking: "Re-ranking Person Re-identification" (CVPR 2017)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

