Gradient LabSign up free

Cheat sheets › Chapter 1

Foundations cheat sheet

What machine learning is, and how data feeds it. Every lesson in one page: the key idea, the pseudocode and the terms.

What is machine learning?

A normal program is a recipe. You write the rules, the computer applies them to data and produces answers.

# Old way: a person writes the rules
rule: if email contains "free money"
    then mark it as spam

# Machine learning: the computer finds the rules
model = new empty model
model.learn(example emails, their right answers)
model.guess(new email)    # uses what it learned

Terms: model, epoch

Data, features and labels

Most ML starts with a table. Each row is one example (here, one house). Each column is one thing we measured about it.

table = load "houses"
# each row = one house
features = columns size, rooms, age    # the clues
label = column price                   # the answer
# 5 rows, 3 feature columns

new_house = [size 120, rooms 3, age 10]    # no price yet
model.guess(new_house)                     # fills in the price

Terms: feature, label, feature vector, prediction

Training and test sets

Here are 20 labeled examples. If we train on all of them, we have nothing left to check whether the model really learned or just memorized.

examples = all 20 labeled examples

shuffle(examples)
train, test = split(examples, 80% and 20%)

model.learn(train)           # study only the training set
score = model.check(test)    # final exam on unseen examples
show score                   # 3 of 4 right = 75%

Terms: test set, training set, validation set

Types of learning

Every example comes with the right answer (its color here). The model learns a rule that separates the classes, like the dashed boundary. Spam filters and price predictors work this way.

# Supervised: examples come with answers
model.learn(examples, answers)

# Unsupervised: no answers, find groups
groups = find_groups(examples, how_many = 3)

# Reinforcement: try things, collect rewards
move = agent.choose_move(where_am_i)
where_am_i, reward = world.do(move)
agent.learn_from(reward)

Terms: agent, reward, policy

Revise with flashcards and quizzes. Free practice for every lesson in this chapter.

Open in the app