Examples
Machine learning learns from data: a collection of examples. Ours are houses sold in Portland, Oregon. Each listing records three things: the living area, the number of bedrooms and the price the house sold for.
One example is one thing we have measured: here, one house. In a dataset each example becomes one row of a table. The first house: 2,104 square feet, 3 bedrooms, sold for $400,000.
Adding every house gives the dataset: one row per example. We show five; the full table in Stanford's CS229 course notes has 47 Portland houses. Real datasets often hold thousands or millions of rows.
Features and labels
Each of these columns is a feature: one measurable property of every example. Here, living area and bedrooms. Features are the inputs, what we know about a house before anyone names its price.
The last column is the label, also called the target: the answer we want a model to learn to predict. Here, the sale price in thousands of dollars. Features are usually written x, the label y.
A model sees an example as numbers. The first house's features form a vector, an ordered list of numbers: x = [2104, 3]. Its label is y = 400. Every row splits the same way.
In Python, the list of rows splits into X, every feature vector, and y, every label. r[:2] takes the first two numbers of a row; r[2] takes the third. Printing X[0] and y[0] shows the first house.
Using the data
Before training we hold some rows back. The training set is what the model learns from. The test set stays hidden until the end, to check the model on houses it never saw. Here: 4 rows train, 1 tests.
Later a new house comes on the market: 1,800 square feet, 3 bedrooms, price unknown. We know its features but not its label. Predicting that missing y from x is the job of the model we train.
What happens
;; step 1/9 · data data a collection of examples example one thing we measured: here, one house each listing records: living area in square feet bedrooms a count price what it sold for, in $1000s
The five houses are the first rows of the Portland housing table in Stanford CS229's lecture notes (A. Ng, T. Ma): living area in square feet, bedrooms, and price in thousands of dollars. The full table has 47 houses. The new house (1,800 square feet, 3 bedrooms) is made up for the example; it is not in the CS229 data.