Code RoomModel comparison lacks random seed
MediumPrep Room Coding #2249

Model comparison lacks random seed

Code reviewCode quality & reviewMid–Senior~15 min

Review this Python experiment-comparison script.

Results flip between runs — sometimes A wins, sometimes B. What's the problem and how do you make this trustworthy?

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.

0:00 of about 15 min
Mark a line and say what kind of problem it is.0 findings
1import numpy as np
2from sklearn.ensemble import RandomForestClassifier
3from sklearn.model_selection import train_test_split
4from sklearn.metrics import f1_score
5 
6def compare(X, y, feature_set_a, feature_set_b):
7 Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.25)
8 def run(cols):
9 m = RandomForestClassifier(n_estimators=300)
10 m.fit(Xtr[:, cols], ytr)
11 return f1_score(yte, m.predict(Xte[:, cols]))
12 fa = run(feature_set_a)
13 fb = run(feature_set_b)
14 print("A:", fa, "B:", fb, "-> pick", "A" if fa > fb else "B")
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.