Vote ensemble outer join

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

Vote ensemble outer join is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Ensemble ranked recommendation lists by outer-joining exploded candidates and re-ranking by weighted vote sum

How to use this skill

Skill file

Vote Ensemble via Outer Join

Overview

When ensembling multiple recommendation submissions that each predict a ranked list of item IDs, explode each list into per-candidate rows, outer-join on (session, item), sum weighted votes, and re-rank. Unlike rank averaging, this handles disjoint candidate sets naturally -- items appearing in more submissions get more votes.

Quick Start

import polars as pl

def vote_ensemble(submission_paths, weights=None, k=20):
    """Ensemble ranked lists by weighted vote counting.
    
    Args:
        submission_paths: list of CSV paths (session_type, labels)
        weights: per-submission weight (default: equal)
        k: number of items to keep per session
    """
    if weights is None:
        weights = [1] * len(submission_paths)
    
    subs = []
    for path, w in zip(submission_paths, weights):
        sub = (pl.read_csv(path)
            .with_columns(pl.col('labels').str.split(' '))
            .explode('labels')
            .with_columns([
                pl.col('labels').cast(pl.UInt32).alias('aid'),
                pl.lit(w).cast(pl.Float32).alias('vote')
            ])
            .select(['session_type', 'aid', 'vote']))
        subs.append(sub)
    
    # Outer join and sum votes
    merged = pl.concat(subs)
    ranked = (merged
        .group_by(['session_type', 'aid'])
        .agg(pl.col('vote').sum().alias('vote_sum'))
        .sort(['session_type', 'vote_sum'], descending=[False, True])
        .group_by('session_type')
        .agg(pl.col('aid').head(k).cast(pl.Utf8).alias('labels'))
        .with_columns(pl.col('labels').list.join(' ')))
    return ranked

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.