Classes and objects
Instrument the ThresholdModel class
Page 6 adds signals that distinguish bad input from component failure in the ThresholdModel class with per-instance cutoffs.
1Learn the idea
Read
Emit stage signals
Instrument the ThresholdModel class with per-instance cutoffs so a run records enough structure to debug offline: counts, latency if relevant, pass/fail of assert Strict(0.8) and Loose(0.4) disagree on score 0.5, and a stable stage name. Redact secrets and raw credentials from every event.
Read
Emit and assert
m=__import__('json')
print(m.dumps({'model':'Strict','threshold':0.8,'n_scores':2,'positives':1}))
Expected evidence: per-instance prediction metrics. Prefer JSON or structured text you can grep in CI over prose logs for python-classes.
Read
Lock signals with a regression test
Turn one historical failure—especially shared mutable class attribute for threshold so instances overwrite each other—into a test that fails if the signal disappears for the ThresholdModel class. Observability without a failing test is optional decoration; observability with a test is part of the python-classes artifact.
Read
Lab notebook: signal schema
Draft a three-field event for the ThresholdModel class: stage, ok, and one domain field derived from assert Strict(0.8) and Loose(0.4) disagree on score 0.5. Add fixture_id or docs_version when content can change. Explicitly list fields that must never appear (tokens, passwords, raw prompts) because storing PII inside repr or dict dumps in logs is in scope for this lab.
Wire one assertion that fails if the ThresholdModel class event is missing after a run. Observability that cannot fail a test will not survive contact with a busy python-classes repository.
Read
Worked judgment
Imagine a teammate opens only your event stream after a bad deploy. Could they tell whether Strict(threshold=0.8), Loose(threshold=0.4), scores=[0.5,0.9] was wrong, whether shared mutable class attribute for threshold so instances overwrite each other returned, or whether storing PII inside repr or dict dumps in logs slipped through? If not, rename fields until those three stories are distinguishable.
Read
Why this stage matters for the ThresholdModel class
At the testing and observability stage for python-classes, the job is narrower than finishing a product demo. You are creating one progressive evidence piece about Strict(threshold=0.8), Loose(threshold=0.4), scores=(0.5,0.9) 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: two handwritten prediction tables before coding the class.
For this page specifically, success looks like a structured event schema locked by a test while still centering the user decision to reuse one predict method across two named models with different thresholds. If you cannot point to a file, command, or assertion that proves that for the ThresholdModel class, stay on this page instead of advancing.
Go deeper
Before you start
Why this matters
Write the single log line or metric event that would tell you whether a bad result came from input vs implementation for the ThresholdModel class. If your line could not tell them apart, redesign it before coding.
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
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.