← All courses
IVYXSTUDIO · COURSE

ML 101

ml-101 · v1.0.0

ivyx

How machines learn: fit a model in two calls, put it against an opponent it has to beat, tell learning apart from memorising, and say how much of your result was the model and how much was the split.

intermediate325 min8 lessonsen
#scikit-learn#machine-learning#regression#evaluation#ai-series#intermediate

What this course is for

By the end of this course you can train a model, measure it against a baseline it has to beat, and say whether it learned the data or memorised it.

What you will be able to do

  • Describe a model as a function chosen by examples, and fit one with fit and predict
  • Build the cheapest thing that could answer your question, and score it before you score anything else
  • Read a coefficient with its unit attached, and refuse a ranking of columns that is really a ranking of units
  • Choose between MAE, RMSE and the worst case by what a miss actually costs
  • Hold rows back before scoring, and check that the rows you held back are representative
  • Draw the training and held out errors against a model's flexibility, and read the gap between them
  • Score on k folds instead of one split, and report the spread next to the mean
  • Run the whole loop on a table you have never seen and write down what the result must not be used for

Who it is for

Learners who finished PANDAS 101 and AI MATH 102, and anyone who can already fit a model in three lines and has never been sure whether the score meant anything

Before you start

  • PANDAS 101, or comfort with reading a CSV, filtering rows and grouping
  • AI MATH 102 for means, spread and what a slope is
  • DATAVIZ 101 is useful for lesson 6 and is not required

Lesson path

Before any model2 lessons

What fitting actually is, and the number you compute before any of it

  1. 1What a model is35 min

    Describe fit and predict as a function chosen by examples, nothing grander

  2. 2The baseline35 min

    Beat the cheapest thing that could answer the question, or admit you have decoration

Fitting lines2 lessons

Several columns at once, what each coefficient means, and how to score the result

  1. 3Linear regression45 min

    Fit on several columns and read a coefficient with its unit attached

  2. 4Measuring error40 min

    Choose MAE or RMSE by what a miss costs, and read the gap between them

The trap2 lessons

Why every score so far was worthless, and the dial that makes it visible

  1. 5Train and test40 min

    Watch a deep tree score a perfect 1.0 on rows it has seen and fail on rows it has not

  2. 6Overfitting45 min

    Sweep a model's flexibility and draw the U curve by hand

Trust2 lessons

How much of a score is the model, and how much of it was the split

  1. 7Cross-validation40 min

    Show that a single split's score is itself a random variable

  2. 8The full loop45 min

    A table you have never seen, start to finish, with the verdict written down

About this course

ML 101: How machines learn

Eight lessons on the smallest honest version of a machine learning project. Fitting a model is two method calls and takes a lesson. The other seven are about the part nobody shows you: finding out whether the thing you fitted is worth anything, which turns out to be most of the job and all of the judgment.

How this course teaches

Same tutor as the rest of the series: predict before you run, and hints that climb a ladder ending in an explanation rather than pasted code. What is different here is that every model in this course succeeds. Fitting always works, a score always comes back, and a number that arrives cleanly formatted is the hardest kind of wrong to notice.

So every graded cell checks a result against a second route to the same question, and the second route is usually cheaper than the first:

assert rating_mae < constant_mae, "what does the best constant manage without looking at a column?"
assert abs(reported - across) < 0.10, "one split says 33.6 percent and five folds say 0.7"
assert set(new["district"]) <= set(flats["district"]), "how many of those were in the training data?"

Three of the eight diagnose cells catch a model that beat something. Every one of them beat the wrong thing.

What you will be able to do

  • Describe a model as a function chosen by examples, fit one with fit and predict, and say why a confident answer from outside the range of those examples is arithmetic rather than evidence
  • Build the cheapest thing that could answer your question and score it first, so that a result has an opponent
  • Read a coefficient with its unit attached, and refuse a ranking of columns that is really a ranking of the units they were recorded in
  • Choose between MAE, RMSE and the worst case by what a miss actually costs, and read the gap between the first two as a measurement of your errors
  • Hold rows back before scoring anything, and check that the rows you held back are a fair stand in for the ones the model will meet
  • Turn a model's flexibility up and down, draw both errors against it, and read the gap rather than either number
  • Score on five folds instead of one split, report the spread next to the mean, and refuse a difference smaller than the noise in the measurement of it
  • Run the whole loop on a table you have never seen and write down what the finished thing must not be used for

The lessons

Before any model

  1. What a model is
  2. The baseline

Fitting lines 3. Linear regression 4. Measuring error

The trap 5. Train and test 6. Overfitting

Trust 7. Cross-validation 8. The full loop

The data

420 used car listings, written to disk by each lesson's setup cell from a fixed seed, so any lesson opens on its own and rerunning is always safe. It is the PANDAS 101 and DATAVIZ 101 forecourt again, a season on and with the odometers turning.

Every property of it feeds a lesson. Depreciation follows the odometer rather than the model year, so the largest coefficient in lesson 3 belongs to the column with the smallest effect and the ranking reverses when you put them in the same unit. The seller rating carries just enough signal to fit and not enough to matter, which is how lesson 2 gets a properly fitted model with a positive R2 that loses to a constant. Five SUVs are on the forecourt at a third of their money with nothing in the file to say why, which is 1.2 percent of the rows owning 51 percent of the squared error in lesson 4. And the export arrives sorted by asking price, which nobody mentions until lesson 5 slices the first 80 percent of it and gets a held out set that is 100 percent SUV.

Lesson 8 opens a second table you have never seen, 300 rental listings in another city, and runs the whole loop on it. The model there beats its baseline by 15 percent and loses to one line of pandas by 37, and the column that explains the difference was in the file the whole time. Lesson 8 removes both files.

Where this course sits

Sixth course of the ivyx AI series and the start of the machine learning wave. PANDAS 101 is the real prerequisite, since every X in this course is a frame you filter and group yourself, and AI MATH 102 supplies the mean, the spread and the slope that a coefficient turns out to be. DATAVIZ 101 is useful rather than required: lesson 6 draws the U curve and holds it to that course's rule, which is that a graded cell asserts against the axes it just drew.

What this course installs is the discipline the rest of the series escalates. ML 102 weaponises it, with a model that scores 95 percent by never saying yes and a scaling step that leaks the answer into the training data. PYTORCH 102 spends a lesson reading loss curves, which is lesson 6's picture with epochs on the horizontal axis. HF 102 makes it bite: a fine tuned model that loses to the zero shot baseline is a real and instructive outcome, and by then you will have met the same shape three times.

Requirements

Python 3, with numpy, pandas, scikit-learn and matplotlib. Verified against scikit-learn 1.9 and pandas 3.0. One name in the course needs a recent version: root_mean_squared_error arrived in scikit-learn 1.4, and before that it was mean_squared_error(y, guess, squared=False).