DSCI 571 Lecture 1: Introduction and a First Model

Introduction, Terminology, Baselines, Decision Trees

Varada Kolhatkar

Focus on the breath!

Announcements

  • Lab 1 has been released.
  • DSCI 571 links:
    • Github page: https://github.ubc.ca/MDS-2026-27/DSCI_571_sup-learn-1_students
    • Course notes: https://ubc-mds.github.io/DSCI_571_sup-learn-1_book/
    • Lecture slides: https://ubc-mds.github.io/DSCI_571-slides/lecture.html

571 Deliverables

The following deliverables will determine your course grade:

Assessment Weight Where to submit
Lab Assignment 1 12% Gradescope
Lab Assignment 2 12% Gradescope
Lab Assignment 3 10% Gradescope
Lab Assignment 4 12% Gradescope
Participation 4% Oral check-ins in lab
Quiz 1 25% PrairieLearn
Quiz 2 25% PrairieLearn

Meet your instructor

  • Varada Kolhatkar [ʋəɾəda kɔːlɦəʈkər]
  • You can call me Varada, V, or Ada.
  • Associate Professor of Teaching in the Department of Computer Science.
  • Ph.D. in Computational Linguistics at the University of Toronto.
  • I primarily teach machine learning courses in the Master of Data Science (MDS) program.
  • Contact information
    • Email: kvarada@cs.ubc.ca
    • Office: ICCS 237

Activity 1


Discuss the following questions with your neighbour.

  • What have you heard about machine learning, or where have you encountered it?
  • What’s one thing you’re excited or unsure about?

Today’s big questions

  • What is machine learning, and when is it useful?
  • How do we represent a prediction problem with features and a target?
  • How do baselines and decision trees learn and make predictions?
  • How do we evaluate predictions and control tree complexity?

AI, ML, and DL

Where do AI, ML, and DL fit?

Quick discussion: which of these might use AI, machine learning, or deep learning?

  • A spam detector 📧
  • A basic calculator ➕
  • A chatbot planning your holiday 💬

What are AI, ML, and DL?

Our focus: learning from examples and applying what we learn to new cases.

Image classification

Searching photos for animals involves image classification. Imagine telling cats and foxes apart. How might we do this with traditional programming? With ML?

Image ID Whiskers Present Face Shape Fur Colour Label
1 Yes Round Mixed Cat
2 Yes Round Brown Cat
3 Yes Pointed Red Fox
4 Yes Pointed Red Fox
5 Yes Round Grey Cat

Who writes the rules?

Traditional programming

We write the rules.

Pointed face + red fur

\(\to\) Predict fox

Machine learning

We provide labeled examples.

Features + cat/fox labels

\(\to\) Learn a prediction rule

What would happen with either approach if we encountered a fox with white fur?

DL approach: example

  • A neural network automatically learns which features to look at (edges \(\rightarrow\) textures \(\rightarrow\) objects).
  • No need to even specify face shape or fur colour. It learns relevant features on its own.

Supervised learning: inputs, targets, and predictions

  • Inputs (\(X\)): observations described by features, such as fur colour and face shape.
  • Targets (\(y\)): labels or values we want to predict, such as cat or fox.
  • Training: learn a model \(f\) relating inputs to targets.
  • Prediction: use the model to predict targets for unseen examples.

When should we use ML?

❓❓ Rules, ML, or human judgment?

Choose a starting point for each problem and explain why. Combinations are possible.

  • (A) Checking whether an email address ends with @student.ubc.ca
  • (B) Predicting which songs a listener might enjoy
  • (C) Awarding a scholarship based on a student’s personal essay

Where could mistakes cause harm, and who should be responsible?

(Optional) AI in the news

Mathematical discovery:

OpenAI reports an AI-generated solution to a major problem about fluid motion.

Emotional support:

About one in five students in an Ontario study reported seeking emotional support from AI. The association with emotional problems does not establish causation.

What would you want to know before trusting an AI system in either setting?

Formulate a prediction problem

Which job might make you happy?

You’ve graduated and have several job offers. Which one would make you happiest?

Happy vs sad employees

Image created by GPT-6 Astra
  • What job attributes would you record?
  • What outcome would you predict, and how would you represent it?

Toy job happiness dataset

Supportive
colleagues
Salary ($) Free
coffee
Boss
vegan
Happy?
0 70,000 0 1 Unhappy
1 60,000 0 0 Unhappy
1 80,000 1 0 Happy
1 110,000 0 1 Happy
1 120,000 1 0 Happy
1 150,000 1 1 Happy
0 150,000 1 0 Unhappy

Each row describes one person in a job. 1 = yes; 0 = no.

Your turn: identify \(X\) and \(y\)

Supportive
colleagues
Salary ($) Free
coffee
Boss
vegan
Happy?
0 70,000 0 1 Unhappy
1 60,000 0 0 Unhappy
1 80,000 1 0 Happy

First three examples: which columns are inputs, and which is the target?

Features \(X\): the four job attributes
Target \(y\): Happy?
Example: one row
\(n = 7\) examples and \(d = 4\) features

Training vs. Prediction

  • Training: learn the mapping

    • Known features \(X\) + known targets \(y\) \(\to\) fitted model \(f\)
  • Prediction: use the mapping

    • New features \(X_{\text{new}}\) \(\to\) fitted model \(f\) \(\to\) predictions \(\hat{y}_{\text{new}}\)

We need known targets to train the model, not to make predictions.

Same job features, different targets

Supportive
colleagues
Salary ($) Free
coffee
Boss
vegan
Happy? happiness_score
0 70,000 0 1 Unhappy 35
1 60,000 0 0 Unhappy 48
1 80,000 1 0 Happy 85
  • Happy or unhappy \(\to\) predict a discrete label \(\to\) classification
  • Happiness score from 0 to 100 \(\to\) predict a numerical quantity \(\to\) regression

Other regression examples: predicting temperature, house price, or travel time.

iClicker 1.1: Classification or regression?

Select all regression problems.

  • A. Predict whether a flight will be delayed.
  • B. Predict a flight’s delay in minutes
  • C. Predict a student’s percentage grade in DSCI 571.
  • D. Predict whether you’ll get a seat on the bus.
  • E. Predict whether you’ll hit snooze tomorrow morning.

Train, predict, and evaluate models using scikit-learn

Separate the inputs from the target

X = toy_happiness_df.drop(columns=['happy?'])
y = toy_happiness_df['happy?']
Object Contains Shape
X Four feature values for each person (7, 4)
y One known happiness label per person (7,)

Keep the answer out of the inputs.

Your turn: predict without the features

Seven training labels: four Happy and three Unhappy

If you must predict the same label for everyone, which label should you choose? How many predictions will be correct?

A baseline gets four out of seven right

Actual Baseline prediction Correct?
Unhappy Happy No
Unhappy Happy No
Happy Happy Yes
Happy Happy Yes
Happy Happy Yes
Happy Happy Yes
Unhappy Happy No

Always predict Happy: accuracy \(= 4/7 \approx 57\%\)
Classification error: \(3/7 \approx 43\% = 1 - \text{accuracy}\)

Fit a baseline with scikit-learn

We’ll use scikit-learn, a Python machine learning library.

from sklearn.dummy import DummyClassifier

dummy = DummyClassifier(strategy='most_frequent')
dummy.fit(X, y);

fit(X, y) learns from the training data.

Here, it finds the most frequent target. This baseline ignores the feature values.

Predict, then check accuracy

dummy.predict(X)
array(['Happy', 'Happy', 'Happy', 'Happy', 'Happy', 'Happy', 'Happy'],
      dtype='<U5')
print(f'Training accuracy: {dummy.score(X, y):.1%}')
Training accuracy: 57.1%

predict(X) returns predicted labels.
score(X, y) compares predictions with known targets.

Method You provide It does
fit(X, y) Features and known targets Learns the model
predict(X_new) Features Returns predicted targets
score(X, y) Features and known targets Returns a default evaluation measure

Why doesn’t predict require y?

We don’t know the answer yet!

Decision trees

Can we do better than the baseline?

Supportive
colleagues
Salary ($) Free
coffee
Boss
vegan
Happy?
0 70,000 0 1 Unhappy
1 60,000 0 0 Unhappy
1 80,000 1 0 Happy
1 110,000 0 1 Happy
1 120,000 1 0 Happy
1 150,000 1 1 Happy
0 150,000 1 0 Unhappy

Propose one yes/no question that separates Happy from Unhappy.

Which question is more effective?

Question No group Yes group Comments
Supportive colleagues? 0 😊,
2 ☹️
4 😊,
1 ☹️
Cleaner split
Boss vegan? 2 😊,
2 ☹️
2 😊,
1 ☹️
Mixed labels
Supportive
colleagues
Salary ($) Free
coffee
Boss
vegan
Happy?
0 70,000 0 1 Unhappy
1 60,000 0 0 Unhappy
1 80,000 1 0 Happy
1 110,000 0 1 Happy
1 120,000 1 0 Happy
1 150,000 1 1 Happy
0 150,000 1 0 Unhappy

Supportive colleagues gives a cleaner split.

How does a tree learn its questions?

  • Learn which feature-based questions to ask, and in what order.
  • At each node, compare candidate questions and choose a split that makes the groups’ labels less mixed.
  • Repeat within each group, until a stopping condition is reached.
  • Each leaf predicts its most frequent training class.

Fit a decision tree

from sklearn.tree import DecisionTreeClassifier

model = DecisionTreeClassifier(max_depth=2, random_state=1)
model.fit(X, y);

Same fit interface. A different learning algorithm.

max_depth=2 allows at most two questions along a prediction path.

Read the learned tree

Root: first question, Branch: answer to a question, Leaf: prediction

Prediction

What would be the prediction for the example below using this tree ?

  • supportive_colleagues = 0
  • salary = 100,000
  • coffee_machine = 0
  • vegan_boss = 1

Prediction with sklearn

  • supportive_colleagues = 0
  • salary = 100,000
  • coffee_machine = 0
  • vegan_boss = 1
test_example = [[0, 100000, 0, 1]]
print("Model prediction: ", model.predict(test_example))
Model prediction:  ['Unhappy']

Does the tree beat the baseline?

model.score(X, y)
1.0
Model Correct / total Training accuracy
Always Happy 4 / 7 57%
Decision tree (max_depth=2) 7 / 7 100%

Yes, on the training data.
We still don’t know how well it predicts happiness for new people.

iClicker Check-in

How are you feeling about the workflow and decision trees?

  • A. I can explain both to a neighbour.
  • B. I understand the ideas but need to review the code.
  • C. I understand the code but need to review how decision trees work.
  • D. I’d benefit from a pause and another example.

Parameters vs. Hyperparameters

Before fit: hyperparameters During fit: parameters
We set max_depth=2. The tree learns to split on salary at 75,000.
This limits the allowed tree depth. It learns another split on supportive_colleagues at 0.5.

Tree depth: the number of edges on the longest root-to-leaf path.

Decision boundary with max_depth=1

  • Points: observed people and their actual labels
  • Shaded regions: the model’s predicted class
  • Decision boundary: where the predicted class changes

Decision stump: a depth-one tree. Which person does it get wrong?

The person earning $150,000 without supportive colleagues.

Decision boundary with max_depth=2

Contrast it with the depth-two tree, which can ask another question within the higher-salary group.

iClicker 1.3: Baselines and trees

Select all true statements.

  • A. Changing salary values must change a most-frequent baseline’s predictions.
  • B. predict needs features; score also needs known targets.
  • C. Decision-tree features must be binary.
  • D. A tree predicts by following a path from root to leaf.

Next: will it work on new examples?

We can now represent a problem with \(X\) and \(y\), compare against a baseline, and fit and read a decision tree.

A model can get every training example right.
What would convince us it has learned something useful?

Lecture 2: evaluating on unseen data, overfitting, and model complexity.

More details on this material: DSCI 571 course notes

Exit ticket

Open the following question on PrairieLearn:

LR1.1. exit-question-decision-trees-lecture

Before today’s lab:

  • Read the question carefully.
  • Write preparation notes in the provided box (about 5 minutes). During lab, discuss the question and explain your reasoning in an oral check-in with your TA to earn participation points.