Code Room
Code reviewHard
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.
Learn the concepts
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.