Module 18 · Learned It or Memorized It?

How do you grade a model honestly?

Lesson 18.2 · Training Data vs. Test Data

Felix · Rosa

Rosa: “What does it score on players it never saw?” Felix: “…I used all of them.”

Felix builds a model to predict rebounds from height, using all 300 NBA players.

It looks great. Rosa asks what it would score on players it hadn’t seen. Felix has none left. He used them all.

Rosa suggests he hide some before he starts next time.

The short answer

Hide a random slice before training and grade only on it. Felix reruns it: 210 players to train, 90 hidden. The training score barely changes. The test score is a little lower and a lot more believable. That gap is the price of honesty, and it’s small when the model actually learned.

Try it yourself

Drag the divider to choose how many players the model trains on. The rest are hidden and used only to grade it.

Height (inches) vs Rebounds per gameLonzo BallElijah BryantMiles BridgesJoe DumarsTony ParkerMichael Porter Jr.Khris MiddletonJakob PoeltlKarl MaloneCJ McCollumSeth CurryZach CollinsTre JonesAaron NesmithMelvin Frazier Jr.Brandon IngramNdudi EbiWalt Lemon Jr.Julius RandleAllen IversonDevin BookerP.J. WashingtonJabari BrownReggie MillerAndrew NembhardGabe VincentJonas ValanciunasRaiQuan GrayTerrell BrandonAlperen SengunRoshown McLeodNaz ReidCharles BarkleyNikola MiroticNorman PowellJarrett AllenJalen DurenBogdan BogdanovicKevin Porter Jr.Buddy HieldMarcus SmartMalaki BranhamHerbert JonesTalen Horton-TuckerDeron WilliamsRichard HamiltonMyles TurnerGlenn RobinsonDevin CannadyBol BolOnyeka OkongwuJaden IveyEric BledsoeEvan MobleyDeandre AytonCameron JohnsonChris PaulReggie JacksonSam CassellJabari Smith Jr.Corey KispertAlec BurksStephen CurryJeremy SochanBones HylandDonte DiVincenzoTyreke EvansPrecious AchiuwaKeegan MurrayJohn StocktonJalen McDanielsDino RadjaTrey Murphy IIITyrese HaliburtonKenyon Martin Jr.Carlos BoozerJae'Sean TateKristaps PorzingisDamian LillardNic ClaxtonMarvin Bagley IIIRussell WestbrookCuttino MobleyKentavious Caldwell-PopeZach LaVineMike ConleyJa MorantShai Gilgeous-AlexanderIsaiah JoeMikal BridgesCarmelo AnthonyLonnie Walker IVAndray BlatcheBrandon ClarkeLuka SamanicJalen SmithMoritz WagnerJalen SuggsLuke KennardLarry JohnsonMarkelle FultzBostjan NachbarKevin HuerterKris DunnJames WisemanJosh GreenRashad McCantsCoby WhiteFlip MurrayJonathan KumingaGerald HendersonJosh HartMarcus Morris Sr.Dwyane WadeBrandon WilliamsCam ThomasKobe BryantKeita Bates-DiopDelonte WestBen McLemoreDe'Andre HunterLeBron JamesZion WilliamsonSpencer DinwiddieShaquille O'NealJaren Jackson Jr.Tim Hardaway Jr.Luka DoncicCam ReddishJeremy LinJeff HornacekBennedict MathurinJosh RichardsonMichael JordanDeni AvdijaGiannis AntetokounmpoKhyri ThomasJosh GiddeyMason PlumleeKevin DurantTobias HarrisImmanuel QuickleyNikola VucevicKlay ThompsonDerrick WhiteZavier SimpsonRJ BarrettGary Trent Jr.Jason RichardsonKarl-Anthony TownsBobby PortisAnthony EdwardsDarius GarlandAl HorfordJay WilliamsIsaiah StewartThomas BryantKelly Oubre Jr.Pascal SiakamAllan HoustonLatrell SprewellJames HardenJalen GreenBam AdebayoMark PricePatrick WilliamsShabazz NapierHarrison BarnesRik SmitsDion WaitersHamidou DialloMalik BeasleyDejounte MurrayBrook LopezTyus JonesKillian HayesCameron OliverJulian ChampagnieCorliss WilliamsonCole AnthonyDahntay JonesJordan ClarksonLauri MarkkanenMac McClungBobby PhillsCade CunninghamJordan HamiltonJayson TatumBison DeleDeMarcus CousinsJaden McDanielsKenneth FariedKyle LowryJerami GrantDoug McDermottAnfernee SimonsWendell Carter Jr.Scottie BarnesDeMar DeRozanSaddiq BeyMalik MonkCarlos DelfinoTrae YoungKawhi LeonardNikola JokicChris BoshJaylen HoardRudy GobertBradley BealPaolo BancheroDaniel GaffordRay AllenKeldon JohnsonJamal MurrayJohn WallDanilo GallinariAnthony DavisNaji MarshallGerald GreenAustin ReavesClyde DrexlerAaron GordonJalen BrunsonChristian WoodBojan BogdanovicTy LawsonLaMelo BallBob SuraDennis SchroderDesmond BaneIsaiah RiderCarl LandryKevin MartinVictor OladipoFranz WagnerJaylen NowellDonovan MitchellPaul GeorgeChris CrawfordDwayne BaconMonte MorrisClint CapelaYao MingDe'Anthony MeltonCaris LeVertD'Angelo RussellSkylar MaysJordan McRaeShaedon SharpeLouis KingAlexey ShvedSasha DanilovicJaylen BrownDomantas SabonisJimmy ButlerChris BoucherMalik SealyKyle KuzmaFred VanVleetMalcolm BrogdonO.G. AnunobyWalker KesslerJuan Carlos NavarroJrue HolidayCaleb MartinKyle AndersonCollin SextonRui HachimuraJordan PooleIvica ZubacLaMarcus AldridgeBruce BrownTyler HerroTari EasonCameron PayneEric GordonDillon BrooksKyrie IrvingTyrese MaxeyAndrew WigginsGrayson AllenGordon HaywardDe'Aaron FoxJusuf NurkicJamal MashburnDevin VassellZach RandolphTerry RozierJohn CollinsLuguentz DortBonzi WellsJalen WilliamsJeenathan WilliamsMax StrusRJ HunterReggie PerryTaurean PrinceKelly OlynykJoel EmbiidQuentin GrimesTraining dotsHidden test dots

Test error: 2

What you just did has a name

Train/test split

Before training, split the data: most of it (often 70 or 80 percent) trains the model, and the rest is locked away.

After training, grade the model on the locked-away part.

The test score is the only number that predicts how it will do in the world.

A few more things

Split at random

Train on the tallest players and test on the shortest and you’ve built Module 6’s lunch line. Shuffle first, then split, so both halves look like the whole.

Never peek

If you adjust the model after looking at the test score, the test data has leaked into training and the score is inflated. Serious teams keep a final test set they look at exactly once.

Small data, big problem

Ashley has sixteen videos. Hold out four for testing and she trains on twelve. Every model she builds is going to be shaky, and the test score will say so. That’s the test doing its job.

Go deeper

The longer version, if you want it.

Validation and cross-validation

Real projects split three ways: training data to fit the model, validation data to tune choices like the threshold or the number of groups, and a test set touched once at the end. Tuning on the test set turns it into more training data and the honest score is gone.

When data is scarce, cross-validation rotates the split: divide into five slices, train on four and test on the fifth, five times, once per slice, and average the five test scores. Every row gets tested exactly once and every row gets used for training. It’s how Ashley’s sixteen videos could be graded without wasting a quarter of them.

Quick check

Owen trains a model on 1,000 reviews, then checks its score on 200 of those same reviews. Is that a test score?

Let’s take it slower

Think of it as grading a take-home exam. If the student wrote the answer key, the exam tells you nothing. So you tear the deck of data in two before the model ever sees it. The bigger pile is study material. The smaller pile goes in a drawer, and the model doesn’t get to look. Train, then open the drawer and grade. The drawer score is the honest one because the model couldn’t have memorized what it never saw. Shuffle before you tear, so both piles look like the whole.

More examples

1

Holding back last season

A model that predicts soccer results is trained on seasons up to last year, and last season stays in a drawer. When it predicts last season’s results, that score is the one to trust. Grading it on the seasons it studied would only show it remembers old scores.

2

The pet recognizer

A team trains a pet-recognizer on 10,000 photos and sets aside 2,000 it never trains on. It scores 98 percent on the training pile and 88 on the set-aside pile. The 88 is what you’d see on your own camera roll, and that gap is the number worth writing down.

Back to the question

So how do you grade honestly?

Show the answer

Hide a random slice before training and grade only on it. Felix reruns it: 210 players to train, 90 hidden. The training score barely changes. The test score is a little lower and a lot more believable. That gap is the price of honesty, and it’s small when the model actually learned.

One last question

Build the honest grading recipe.

Tap the pieces in order. Tap one again to take it back.

…
Talk Card

Talk Card · 18.2

Hide a slice of the data before training, then grade the model only on the slice it never saw. That test score is the one that predicts the real world.

Data to AI · pettigrewlab.com/learn

Next lesson