← 返回 reddit 的题目列表MLE Live Coding: EDA + Post-Category CTR
类型:qbank
Live Jupyter notebook session. Load a small post-engagement dataset (per-row reading time across post categories plus a click label), do quick EDA, build a CTR classifier, and discuss model choice and metrics with the interviewer.
Requirements
The interviewer ships a small JSON dataset over the chat or pre-loaded in the CodeSignal / Jupyter notebook. Each row is one post impression for a user, and the goal is to predict whether the user clicks the post. The row shape is:
{
"hours_spent_reading_a": float, # hours the user historically spent on category-A posts
"hours_spent_reading_b": float, # hours on category-B posts
"hours_spent_reading_c": float, # hours on category-C posts
"current_post_category": "A" | "B" | "C", # category of the post currently being shown
"click": 0 | 1 # binary label: did the user click this post
}
The first three columns describe the user's historical time-spent-reading profile per category; current_post_category is the category of the post being scored; click is the target.
The data is intentionally clean — no missing values, no major class imbalance, straightforward numeric features plus one categorical — to remove cleaning noise from the time budget and keep the focus on modeling judgment rather than data wrangling.
Deliverables in the 60-minute round:
Load the JSON into a pandas DataFrame and inspect the schema.
Quick EDA: feature distributions, target balance, pairwise relationships, basic correlations.
Preprocess: one-hot encode the category, split the data.
Train and compare at least two models (commonly: dummy baseline → logistic regression → random forest → XGBoost).
Discuss model choice and explain the trade-offs the interviewer asks about.
Pick and justify an evaluation metric.
Examples
A minimal load-and-inspect confirms this is binary classification, that the three hours columns are already usable floats, and that only the category needs encoding:
import json, pandas as pd
with open("data.json") as f:
data = json.load(f)
df = pd.DataFrame(data)
df.head(); df.dtypes; df["click"].value_counts()
Notes
Time is the binding constraint. Most candidates finish baseline + logistic regression + one tree model; cross-validation and hyperparameter tuning are aspirational and the interviewer is fine with skipping them.
The standard EDA toolbox: df.describe(), df.value_counts(), sns.pairplot, target-vs-feature box plots. Pairplot delivers the most signal per line of code for a low-dimensional tabular dataset and is the most-cited helper.
Categorical encoding for current_post_category: one-hot is the safe default for linear models; tree models accept label encoding directly.
Model-choice follow-ups invariably probe: (1) why pick logistic regression as a baseline (interpretability, linear-decision-boundary intuition), (2) why move to a tree model (interaction effects between hours-read features and current category), (3) why XGBoost over random forest (regularization, sequential boosting, generally higher leaderboard performance for tabular). Also be ready for why NOT SVM, k-NN, or a neural network — for a tiny, low-dimensional, mostly-numeric tabular set they add tuning cost and overfitting risk without beating boosted trees, and a full net is overkill at this data scale.
Metric follow-ups: accuracy is fine when classes are balanced (this dataset is); ROC-AUC and precision-recall-AUC handle the imbalanced case; F1 balances precision and recall; log-loss is the right choice when probabilities feed a downstream ranking. Frame the final pick around product goals — accuracy when error costs are symmetric, precision or recall when one mistake type dominates, ROC-AUC to compare ranking quality across thresholds. Interviewers explicitly ask "why this metric and not that one," so defend the choice; accuracy alone is insufficient once business costs are asymmetric.
Interviewers typically allow syntax lookups for pandas / sklearn / xgboost API. They do not allow AI chat assistants. Verbalize lookups ("let me check the xgboost.XGBClassifier parameter name") rather than silently switching tabs.
The round is friendly and practical: the interviewer allows syntax lookups, gives small hints when a candidate makes a typo, and grades sound modeling choices and reasoning — running out of time for CV or tuning is not penalized on its own, as long as the model choices and reasoning hold up.
Deployment / monitoring follow-ups are rare at the phone-screen stage. Save them for onsite ML system design.
A 2026 variant ships dirty data instead of clean: missing values and class imbalance (~20% positive label). Budget time to impute or drop missing rows and to handle the imbalance (class weights, resampling, or threshold tuning), and report F1 (or PR-AUC) rather than raw accuracy. Light feature engineering — e.g. normalizing time-spent per user — is rewarded; strong candidates reach F1 > 0.95 on the held-out split.
Canonical preprocessing shape
Separate features/target, one-hot the category (keep all levels for linear models — drop_first=False is a safe default), and stratify the split so the target ratio is preserved:
from sklearn.model_selection import train_test_split
X = df.drop(columns=["click"])
y = df["click"]
X = pd.get_dummies(X, columns=["current_post_category"], drop_first=False)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)
Optionally standardize the hours features for the linear model; tree models don't need it.
If the interview weren't time-boxed
Good "with more time" answers extend beyond CV and hyperparameter tuning to: threshold tuning, feature engineering (interaction terms between the historical reading profile and the current category — e.g. hours spent on the current category), calibration analysis if predicted probabilities feed downstream ranking, and error analysis by category to see where the model fails.
Preparation
Drill a 15-minute end-to-end notebook: load JSON → pandas → quick EDA → train logistic regression + XGBoost → ROC-AUC + log-loss + confusion matrix. Time yourself.
Memorize the canonical sklearn API entry points (fit, predict, predict_proba, cross_val_score, train_test_split) cold. Looking them up burns budget.
Pre-write a 5-line plotting snippet (pairplot + target-coloring) you can paste in. Plot quality is graded informally — having one good plot beats three forgettable ones.
Rehearse the model-tradeoff narrative out loud: dummy baseline → linear → trees → boosted trees, one sentence per step, with the reason for each transition, plus a one-liner on why not SVM / k-NN / a neural net. The interviewer will ask.