Code Room
Code reviewHardcr-g632
Subject Ml evaluationLevel Senior–Staff~20 minCommon in ML systems · Databases & SQL interviewsIndustries Software development

Question

Review this Python scoring code.

Accuracy is mediocre and inconsistent even though the model is good. Find the alignment bug.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
import numpy as npimport pandas as pdfrom sklearn.metrics import accuracy_score def score(model, df):    # df has features + a 'label' column; some rows were dropped upstream    feats = df.drop(columns=["label"])    feats = feats.dropna()                     # drop rows with missing features    preds = model.predict(feats.values)        # numpy array, length = len(feats)    labels = df["label"].values                # length = len(df)    return accuracy_score(labels[: len(preds)], preds)
Run or narrate your approach, then ask the coach.