Page 1 of 8~112 min topic

Classes and objects

Frame the ThresholdModel class experiment

Page 1 sets a falsifiable claim for the ThresholdModel class with per-instance cutoffs before any implementation work begins.

~14 min this pageExperiment brief

1Try it yourself

Playground

Object form builder

Build a Message class mentally: fields role + content, then call preview().

class Message:
  # role…
  # content…
  # preview()…

2Learn the idea

Read

Name the deliverable and claim

Success is not “I followed the tutorial.” Success is producing evidence that: strict and loose instances return different Booleans for the same score list. The accepted input is narrow on purpose: model name, threshold, and numeric scores passed to predict. That narrowness is what lets you inspect every field and prevents a toy demo from being narrated as a production system.

Record the baseline you must beat: two handwritten prediction tables before coding the class. If the finished artifact cannot beat that baseline on the fixture below, stop and revise the claim before writing more code.

Read

Inventory the fixture

print({'models':['Strict@0.8','Loose@0.4'],'shared_behavior':'predict(scores)->bool list'})

Expected evidence: two named cutoffs sharing predict. Treat the printout as a claim about this fixture, not as proof that the toolchain merely started.

Read

Spot misleading success early

For the ThresholdModel class with per-instance cutoffs, a decorative win often looks like a clean run that never checks assert Strict(0.8) and Loose(0.4) disagree on score 0.5. Write the metric down now so later pages cannot redefine success after the fact. Also note the operational threat you will eventually gate on: storing PII inside repr or dict dumps in logs.

Read

Lab notebook: claim before code

For python-classes, write the claim on a sticky note in this exact shape: “Given model name, threshold, and numeric scores passed to predict, the ThresholdModel class will …”. Fill the ellipsis with the observable part of: strict and loose instances return different Booleans for the same score list. Tape the baseline beside it: two handwritten prediction tables before coding the class. If someone later replaces your metric with a vibe check, the sticky note is how you push back.

Also sketch the one-sentence user story: a person uses this output to reuse one predict method across two named models with different thresholds. If that sentence needs a dashboard, a model zoo, or five services, the lab scope is too wide—shrink the fixture (Strict(threshold=0.8), Loose(threshold=0.4), scores=[0.5,0.9]) until the story fits on one screen.

Read

Worked judgment

Decide now whether live network calls are allowed on page 1. For this lab they usually are not; inventory and contracts should run offline against Strict(threshold=0.8), Loose(threshold=0.4), scores=[0.5,0.9]. Note the metric you will eventually require (assert Strict(0.8) and Loose(0.4) disagree on score 0.5) so page 4 cannot invent a softer target. The characteristic failure to keep in mind is shared mutable class attribute for threshold so instances overwrite each other.

Read

Why this stage matters for the ThresholdModel class

At the experiment brief 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 falsifiable claim and baseline written before coding 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.

Object-oriented programming glossary

Next

Go deeper

Before you start

Why this matters

On paper, write the user decision this lab supports: reuse one predict method across two named models with different thresholds. Then write one sentence naming what could look successful while actually being wrong for this claim—focus on shared mutable class attribute for threshold so instances overwrite each other. Keep both sentences beside the fixture inventory you run next.

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.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. What exact claim can this fixture disprove?
2. Which baseline prevents a decorative success story?
3. What result would make you stop before implementation?
4. Did you name the metric (assert Strict(0.8) and Loose(0.4) disagree on score 0.5) up front?

All responses are required.