Prediction: your first ML idea
Build the first working threshold prediction game
Page 3 implements the shortest complete path for the threshold tuner on five labeled scores with inspectable intermediate values.
1Learn the idea
Read
Implement the minimal working path
Build only what the claim requires: for a chosen threshold, accuracy and confusion counts are exact on the fixture. Prefer boring, deterministic code over frameworks you cannot yet explain. Run the path twice; identical output on this fixture is a feature, not a lack of creativity.
Read
Run the working path
data=[(1,0.9),(1,0.6),(0,0.4),(0,0.2),(1,0.55)]; thr=0.5
pred=[int(s>=thr) for y,s in data]
tp=sum(y==1 and p==1 for (y,_),p in zip(data,pred))
fp=sum(y==0 and p==1 for (y,_),p in zip(data,pred))
tn=sum(y==0 and p==0 for (y,_),p in zip(data,pred))
fn=sum(y==1 and p==0 for (y,_),p in zip(data,pred))
acc=sum(y==p for (y,_),p in zip(data,pred))/len(data)
print({'acc':acc,'tp':tp,'fp':fp,'tn':tn,'fn':fn})
Expected evidence: acc and confusion counts. Read each printed intermediate as part of the argument that the path works—not as decoration.
Read
Trace one input end to end
Narrate the journey from raw input to result for a single example from 5 (truth, score) pairs. If you cannot name an intermediate, the implementation is still too opaque for this lab. Only after this path is solid should you generalize data sources or UI.
Read
Lab notebook: intermediates worth printing
While implementing the threshold prediction game, print or log at least three intermediates that map to the claim (for a chosen threshold, accuracy and confusion counts are exact on the fixture). Good intermediates are values a teammate could recompute with a calculator or diff. Bad intermediates are framework traces you cannot explain.
Re-run with 5 (truth, score) pairs twice. If the second run differs, either the path is nondeterministic (document the seed) or you have hidden global state—both are lab bugs until named.
Read
Worked judgment
Stop adding features once the path supports choose a cutoff that balances errors without claiming generalization from five rows. Extra UI, extra tools, or extra models belong in later chapters. The mastery bar for this page is simply: a deterministic end-to-end path with intermediates.
Read
Why this stage matters for the threshold prediction game
At the implementation stage for prediction-game, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about 5 (truth, score) pairs that later pages inherit without redefining success. Keep that fixture small enough to inspect by hand, keep outputs copy-pasteable as text, and refuse to narrate this baseline as if it were a production SLA: confusion counts computed by hand at threshold 0.5.
For this page specifically, success looks like a deterministic path with printed intermediates while still centering the user decision to choose a cutoff that balances errors without claiming generalization from five rows. If you cannot point to a file, command, or assertion that proves that for the threshold prediction game, stay on this page instead of advancing.
Go deeper
Before you start
Why this matters
Without running code, predict the final output for fixture 5 (truth, score) pairs. Name one intermediate value that would prove the prediction. Then answer: what could look successful while actually being wrong at this stage for the threshold prediction game?
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.