Code Room
Code reviewMediumcr-g624
Subject Ml evaluationLevel Mid–Senior~16 minCommon in ML systems interviewsIndustries Software development

Question

Review this Python model-evaluation routine.

It always selects max_depth=None with accuracy 1.0. Is that the best model?

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
from sklearn.tree import DecisionTreeClassifierfrom sklearn.metrics import r2_score, accuracy_score def pick_best_depth(X, y, depths=(2, 5, 10, None)):    best, best_score = None, -1    for d in depths:        model = DecisionTreeClassifier(max_depth=d, random_state=0)        model.fit(X, y)        score = accuracy_score(y, model.predict(X))  # how good is it?        print(d, score)        if score > best_score:            best, best_score = d, score    print("best depth:", best)    return best
Run or narrate your approach, then ask the coach.