Predicting Video Engagement Scores: Analytics Vidhya Job-a-thon, Feb 2022

My approach to the Job-a-thon engagement score problem: group-by features, XGBoost and SHAP, plus the gap between my local score and the leaderboard and what caused it.
Hackathon
Machine Learning
Author
Published

March 3, 2022

In February 2022 I entered Analytics Vidhya’s Job-a-thon, a hiring hackathon. My submission finished 7th on the private leaderboard (15th on the public one), with an R² of 0.465.

Code and approach slides: Zilch123/Analytics-Vidhya-Jobathon-Feb2022

The problem

A video platform gives each video an engagement score for each user, based on how that user likes, comments on and shares it. The task was to predict that score for unseen user and video pairs. The metric was R².

Each row has:

Column Meaning
user_id, video_id, category_id Who watched what, and its category
age, gender, profession About the user
followers Users following the video’s category
views Total views of videos in that category
engagement_score The target, from 0 to 5

The training set had about 89,000 rows.

The business reason is recommendations. If you can predict how engaging a video will be for a user, you can recommend better content, and decide which content to push to a wider audience.

Feature engineering

The raw columns don’t say much on their own. What matters is history: how engaged this user usually is, and how engaging this video usually is. So most of the work went into group-by features:

  • Mean engagement per video (video_id_engagement_score_mean)
  • Mean engagement per user (user_id_engagement_score_mean)
  • Mean engagement per age
  • Per-user averages of category and views, and the user’s most-watched video
df_ue = df.groupby('user_id')['engagement_score'].agg(['mean']) \
        .rename(columns={'mean':'user_id'+'_'+'engagement_score'+'_mean'}).reset_index()
df = df.merge(df_ue, how='left', on= 'user_id')

The test set gets the same features by merging in the averages calculated on the training data.

Apart from that:

  • Label-encoded gender and profession.
  • Capped extreme followers and views values using the IQR method.
  • Scaled everything with StandardScaler.
  • Dropped the raw user_id, video_id and age once their averages were in.

Model

I used XGBoost. I tuned the main settings with grid search, then fine-tuned the number of trees by hand:

model = xgboost.XGBRegressor(n_estimators=191, max_depth=7, learning_rate =0.1,
                             subsample=0.7, colsample_bytree=0.8, gamma=6)

I also tried feature selection with SelectFromModel, but dropping features barely moved the score, so I kept them all.

What the model learned

SHAP shows the user’s average engagement is by far the strongest signal, followed by the video’s average engagement:

Mean absolute SHAP value per feature

SHAP beeswarm: high user and video averages push the prediction up

That makes sense. Some people engage with everything and some with nothing, and some videos are just more engaging. Demographics like gender, profession and age add very little once you know a user’s history.

The gap between my score and the leaderboard

Results, and the distribution of training scores (blue) against my test predictions (orange)

The test set’s labels were hidden. You upload predictions, and the platform scores them, so your own validation split is the only guide you have while building the model. Some drop between that and the final score is normal.

On my own 80/20 split the model scored an R² of about 0.71. On the leaderboard it scored 0.465. A gap that big is the most useful thing I took away from this competition.

The cause is target leakage in the group-by features. I calculated the per-user and per-video averages on the whole training set before splitting it. So each row’s own engagement score was baked into its own feature, and my local test rows weren’t really unseen. The model looked better than it was.

On the real test set those averages come only from other rows, so the advantage disappears. The distribution plot hints at this too: my test predictions (orange) are bunched in the middle, while real scores (blue) are spread out.

What I’d do now:

  • Calculate target averages out-of-fold. For each fold, compute the averages only from the other folds, so a row never sees its own target.
  • Smooth the averages for users and videos with few rows, by blending them with the overall mean.
  • Validate the way the test set is built. If test users also appear in training, a random split is fine once the leakage is fixed. If not, split by user.

A production design

The approach document also asked how this would run for real. I sketched a design with Kafka for user events, SQL with a Redis cache, models tracked in MLflow, serving on Kubernetes behind a load balancer, and drift monitoring that triggers retraining through a CI/CD pipeline.

Proposed production architecture

Takeaways

  • For user and item data, history features (average behaviour per user and per item) do most of the work.
  • Target-mean features are powerful and easy to leak. Calculate them out-of-fold.
  • If your local score and the leaderboard disagree badly, look for leakage before tuning anything.