Machine learning for predictions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Machine learning for predictions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does machine learning use to learn patterns?
A Past data used to train a model
B A fixed set of rules typed in by hand for every case
2. Which describes the model in machine learning?
A The raw spreadsheet of past data before any learning happens
B What is produced after training and is used to predict outcomes for new data
3. A model predicts whether a student will pass or fail. What type of prediction is this?
A Classification
B Numeric prediction
4. A model predicts next month's sales in dollars. What type of prediction is this?
A Classification
B Numeric prediction
5. A model is trained on past house sales. Which is the new data?
A The details of a house that has not been sold yet
B The sale prices already recorded in the training data

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1model.fit(X_train, y_train) Aresult = model.predict(student) # 'Pass'
2model.predict(X_new) BTesting a model only on the data it was trained on does not show how well it predicts new data.
3Classification predicts a category, such as whether a student will pass or fail CUses the trained model to predict outcomes for new data it has not seen before
4Numeric prediction estimates a number, such as next month's sales in dollars DTraining data needs both the inputs and the known outcomes from past data. Without known outcomes the model has nothing to learn from.
5model.fit(X_new) # train on data with no known outcomes Esales = model.predict(month) # 4250.50
6model.predict(X_train) # then claim it works well on new data FTrains the model on past data so it can learn the patterns linking the inputs to the known outcomes

Definitions

machine learning

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
trainingData ← load("sales.csv") model ← _____(trainingData)
2.
pastResults ← load("results.csv") model ← train(___________)
3.
model ← train(pastStudents) label ← _______(model, newStudent)
4.
label ← predict(model, newStudent) IF label _ "Pass" THEN
5.
model ← train(pastMarks) prediction ← predict(model, 6) OUTPUT __________

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A X = [[20, 5], [35, 8]]
B y = ['no', 'yes', 'yes']
C model = Classifier()
D model.fit(X, y)
Question 2
A X = [[1200], [1500], [1800]]
B y = [300, 400, 500]
C model = Regressor()
D model.predict(X, y)
E print(model.predict([[900]]))
Question 3
A X = [[8, 9], [3, 4], [9, 8]]
B y = ['pass', 'fail', 'pass']
C model = Regressor()
D model.fit(X, y)
Question 4
A train = new_row
B model = learn(train)
C guess = model.predict(new_row)
Question 5
A price_model = Classifier()
B sizes = [80, 110, 150]
C prices = [310, 450, 520]
D price_model.fit(sizes, prices)

Answer Key

Machine learning for predictions
Section A: Quick Questions
Q1
A — Past data used to train a model
Q2
B — What is produced after training and is used to predict outcomes for new data
Q3
A — Classification
Q4
B — Numeric prediction
Q5
A — The details of a house that has not been sold yet
Section B: Match the Pairs
Q1
model.fit(X_train, y_train) → Trains the model on past data so it can learn the patterns linking the inputs to the known outcomes
Q2
model.predict(X_new) → Uses the trained model to predict outcomes for new data it has not seen before
Q3
Classification predicts a category, such as whether a student will pass or fail → result = model.predict(student) # 'Pass'
Q4
Numeric prediction estimates a number, such as next month's sales in dollars → sales = model.predict(month) # 4250.50
Q5
model.fit(X_new) # train on data with no known outcomes → Training data needs both the inputs and the known outcomes from past data. Without known outcomes the model has nothing to learn from.
Q6
model.predict(X_train) # then claim it works well on new data → Testing a model only on the data it was trained on does not show how well it predicts new data.
Section C: Definitions
Q1
machine learning — Training a model on past data so it learns patterns and can predict outcomes for new data, such as a category (classification) or a number (numeric prediction).
Section D: Fill in the Blanks
Q1
trainingData ← load("sales.csv") model ← train(trainingData)
Q2
pastResults ← load("results.csv") model ← train(pastResults)
Q3
model ← train(pastStudents) label ← predict(model, newStudent)
Q4
label ← predict(model, newStudent) IF label = "Pass" THEN
Q5
model ← train(pastMarks) prediction ← predict(model, 6) OUTPUT prediction
Section E: Spot the Error
Q1
B — Training data needs one known outcome for every row. X has 2 rows, so y must have 2 labels, not 3.
Q2
D — The model must be trained on past data with fit(X, y). predict() is only used afterwards on new data, so line 4 should be model.fit(X, y).
Q3
C — The outcomes are categories (pass or fail), so this is classification. It needs Classifier(), not a numeric Regressor().
Q4
A — A model learns from past data with known outcomes. new_row is the data to predict, so train should be past_results.
Q5
A — Prices are numbers, so this is numeric prediction. It needs Regressor(), not a Classifier(), which predicts categories.