Beyond a Straight Line
Some relationships curve: an orchard's harvest grows with rain, then drops when there's too much. Bend a linear model with polynomial features, try a regression tree that asks yes-or-no questions, and compare all three honestly on the same test set against a baseline, noticing the first sign of a model that memorized its examples. The running example is an orchard's apple harvest.
Updated
Curves and Trees
- Curves with Polynomial Features (Journeyman): When the label rises and then falls, a straight line misses both ends, but adding a squared copy of a feature lets a linear regression draw a curve; PolynomialFeatures makes those columns, fit on the training rows and used to transform both parts, and a high degree swings wildly at the edges of the data.
- Regression Trees (Journeyman): A regression tree guesses a number by asking yes-or-no questions about the features and answering with the average label of the training rows that end in the same leaf, so its guesses are steps, never outside the range of the training labels, and a tree with no depth limit memorizes its training rows.
Choosing Between Models
- Comparing Regression Models (Journeyman): Models are compared fairly only on the same split, with the same metric and a baseline in the table, and putting each model's training error beside its test error shows which ones memorized; the simplest model that's good enough is usually the one to keep.
Exercise: Orchard Harvest Models
- Exercise: Orchard Harvest Models (Journeyman): Write three functions that make curve features with PolynomialFeatures, build a regression tree with a depth limit and a seed, and compare models fairly on Hilltop Orchard's 200 harvests, each fit on the same training trees with its training and test errors side by side, and let pytest check them.
Up Next: Predicting Categories
- Up Next: Predicting Categories (Journeyman): Look back at what Module 2 taught, fitting lines, splitting data, measuring error against a baseline, curves, trees and fair comparisons, try a short harvest guide for the orchard with all of it, and see what Module 3 adds, models that guess a category, such as spam or not, and ways to count which mistakes they make.