Machine Learning Mechanics – �Terminology and Techniques
Lecture 3
Framing ML Problems and ML Techniques and Terminologies
EECS 189/289, Fall 2025 @ UC Berkeley
Joseph E. Gonzalez and Narges Norouzi
EECS 189/289, Fall 2025 @ UC Berkeley
Joseph E. Gonzalez and Narges Norouzi
EECS 189/289, Fall 2025 @ UC Berkeley
Joseph E. Gonzalez and Narges Norouzi
Join at slido.com�#2826097
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
2826097
Goals For Today
2826097
Today We Introduce Scikit-Learn
Widely used python �package for:
in Machine Learning.
2826097
Which of these libraries have you used before?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
2826097
ML Lifecycle
L
M
P
O
LEARNING PROBLEM
PREDICT & EVALUATE
MODEL DESIGN
OPTIMIZATION
2826097
ML Lifecycle
L
LEARNING PROBLEM
2826097
Example: FashionHub
We are launching a new fashion trading website where people can upload pictures of clothing they want to trade.
What do we want to predict?
What data do we have?
How would we evaluate success?
Type of Clothing
Labeled Pairs
Overall Accuracy?
2826097
ML Lifecycle
L
LEARNING PROBLEM
Understand the Data!
(Look at the data!)
2826097
How to Look at the Data
The Data
Labels
(Optional)
Features
2826097
Demo
Understanding the
Machine Learning Problem
and
Looking at the Data
2826097
Taxonomy of�Machine Learning
Supervised Learning
Labeled Data
Unsupervised
Learning
Unlabeled Data
Quantitative�Label
Dimensionality�Reduction
Clustering
Categorical�Label
Reinforcement
Learning
Alpha Go
Reward
Classification
Regression
Stock
Prediction
2826097
Supervised Learning�Learning from examples (demonstrations)
The “training data” consists of examples of a functional relationship.
Supervised Learning
Quantitative�Label
Categorical�Label
Classification
Regression
Stock
Prediction
2826097
Classification Problems
The labels are discrete classes or categories.
Discrete labels are often “encoded” as numbers (but should be treated as classes)
Two main types of classification problems:
*Funny scene in silicon valley where a binary classifier was trained for food prediction.
Classification
2826097
ML Lifecycle
L
LEARNING PROBLEM
Understand the Data
✅
Learning�Setting
✅
Train-Test
Split
2826097
How will we evaluate the model?
We are about to train a model using data.
How will we know if the model has “learned” from our data?
Why is memorizing the data (exam) not good?
The Exam Analogy:
What would happen if we gave everyone access to the exam and solutions (the data) to study (train) for the exam?
2826097
Generalization
Generalization in machine learning is the ability of a model to perform well on new, unseen data sampled from the same distribution as its training data.
To evaluate generalization,�we need a method to evaluate�the model’s performance on �new data not used for �training.
Training Data
New, Unseen Data
Probably a better model?
2826097
Evaluating generalization using the�Train-Test Split
The train-test split is the standard technique we use to evaluate generalization in machine learning:
Data
Test
Train
Train - Test
Split
You should only use the test dataset once �after developing and training the model.
Why?
If you use the test data to tune the model,�the test data no longer measures generalization.
2826097
Evaluating generalization using the�Train-Test Split
The train-test split is the standard technique we use to evaluate generalization in machine learning:
Data
Test
Train
Train - Test
Split
You should only use the test dataset once �after developing and training the model.
Why?
If you use the test data to tune the model�the test data no longer measures generalization.
But what if I want to peek at the test data�to tune for better generalization?
2826097
The Validation Split
The validation dataset is used to evaluate generalization performance during the model development process.
Data
Test
Train
Train - Test
Split
Train - Val.
Split
Train
Val.
Fit (train) the model using the training data.
Tune the model design using the validation data.
2826097
The Train-Validation-Test Split Analogy
You can think of the train, validation, and test splits as how you might study for an exam.
Test
Train
Val.
Practice question and answer pairs that you use to study for the exam. (Go to discussion!)
Practice exam evaluates if your studying process is working (or if you need to study more).
The exam is how we evaluate if you should pass the class.
2826097
Demo
Train-Test-Validation Splits
2826097
ML Lifecycle
L
M
LEARNING PROBLEM
MODEL DESIGN
2826097
Feature Engineering
Feature engineering is the process of selecting and encoding input features from the raw features.
2826097
Encoding Numerical Data
Numerical features (numbers) are often used without modification.
However, there are a few important exceptions:
2826097
One-Hot Encoding
One-hot Encoding takes a categorical feature (e.g., color, shape) and generates multiple binary features (one for each possible value) and assigns 1 to the feature column with the original value.
Color |
Red |
Green |
Red |
Blue |
Blue |
Yellow |
Missing |
Color:Red | Color:Blue | Color:Green | Color:Yellow | Color:Missing |
1 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 0 |
1 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 0 | 0 |
0 | 1 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 1 |
2826097
Encoding Numerical Data
Numerical features (numbers) are often used without modification.
However, there are a few important exceptions:
2826097
Feature Standardization
2826097
Encoding Text Data
There are several methods for encoding a string of text:
All techniques produce a high-dimensional vector representation of a string.
2826097
Bag-of-words Encoding
Each word in the vocabulary is encoded as a separate column and the occurrence or count of that word is stored in each column:
Stop words (e.g., the, is, of…) that contain minimal information are often dropped from the vocabulary.
“Learning about machine�learning is fun.”
0
0
1
2
1
learning
aardvark
machine
fun
…
…
…
…
0
zyzzyva
aardwolf
Vector
2826097
In graduate school, Prof. Gonzalez moved into a new building that had no art.
So, he secretly installed this “art piece” on the ML floor of the new building.
Do you see the stop word?
There used to be a dustbin and broom
… but the janitors got confused …
New buildings need
ML inspired art!
2826097
Encoding Image Data
Images can be thought of as 3 dimensional tensors:
All techniques produce a high-dimensional vector representation of an image.
Color
Channel
Width
Height
Flatten
…
2826097
Featurization with Scikit-Learn
Scikit-Learn has a large collection �of data transformations to aid in �the feature engineering process.
Many of them have the form:
from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder() # Constructor
ohe.fit(df[["color"]]) # Fit
ohe.transform(df[["color"]]) # Transform
2826097
Demo
Feature Engineering
2826097
ML Lifecycle
L
M
LEARNING PROBLEM
MODEL DESIGN
Feature
Engineering
✅
Model
Family
2826097
Machine Learning�as Function Approximation
Feature
Vectors
Output (Y)
Input (X)
Learned�Function
(Learned?)
Featurization
2826097
Machine Learning�as Function Approximation with �(Learned) Features
Feature
Vectors
Output (Y)
Input (X)
Learned�Function
(Learned?)
Featurization
2826097
Generic Function Approximation
Input (X)
Feature
Vectors
Output (Y)
Learned�Function
(Learned?)
Featurization
2826097
The Linear Regression Model Family
The hypothesis space is all lines parametrized by real-valued slopes and intercepts.
2826097
Inductive Biases
The set of assumptions made in the model design to enable generalization beyond the training data.
No Free Lunch Theorem in ML: there is no universally best model – need to choose the model with the right inductive biases.
Example:
Test Point
Infinitely many models fit the data
Choosing the model family (e.g., linear) is introducing an inductive bias.
2826097
Inductive Biases in �Features and the Model
Feature
Vectors
Output (Y)
Input (X)
Featurization
2826097
What inductive bias assumptions are made with the bag-of-words encoding?
The Slido app must be installed on every computer you’re presenting from
Do not edit�How to change the design
2826097
Complexity:�Linear Models vs Non-Linear Models
Nonlinear models are more expressive and can represent more complex relationships.
Linear
Non-Linear
Regression
Non-Linear
Linear
Classification (Decision Boundary)
Decision Boundary
Are non-linear models better?
2826097
Complexity and Overfitting
“Sweet Spot”
Overfitting
Underfitting
Raw data
Fit models to samples of data
More complex isn’t always better.
2826097
Regularization
Regularization is the process of adding constraints or penalties to the learning process to improve generalization.
�
Many models and learning algorithms have methods to tune the regularization during the training process.
Overfitting
Underfitting
More Regularization
“Sweet Spot”
2826097
Parametric vs. Non-Parametric Models
Voronoi
Diagram
https://en.wikipedia.org/wiki/Voronoi_diagram
Training Data
2826097
Choosing the Model Family
2826097
Logistic Regression Model Family
Linear Decision Boundary
2826097
ML Lifecycle
L
M
O
LEARNING PROBLEM
MODEL DESIGN
OPTIMIZATION
2826097
Iterative Optimization Algorithms
Lecture 5
Lecture 6
Lectures 10-11
2826097
Hyperparameters
for hp1 in [0.1, 1, 10]:
for hp2 in [0.1, 1, 10]:
model = MyModel(hp1=hp1, hp2=hp2)
model.fit(X_train, y_train)
error[hp1, hp2] = error(y_val, model.predict(X_val))
hp1_best, hp2_best = arg_min(error)
| 0.1 | 1 | 10 |
0.1 | .8 | .7 | .7 |
1 | .4 | .2 | .3 |
10 | .5 | .6 | .6 |
2826097
Training vs Validation Accuracy
When tuning regularization hyperparameters against the validation dataset, it is common to see plots where
Better Fit
More Regularization
Sweet Spot
Sweet Spot
2826097
ML Lifecycle
L
M
P
O
LEARNING PROBLEM
PREDICT & EVALUATE
MODEL DESIGN
OPTIMIZATION
2826097
Making Predictions
Inference is the process of making predictions with a model.
Many modern techniques predict distributions (e.g., ChatGPT).
Pullover
2826097
Evaluation Metrics
How do we measure success of a model at test time?
Are all types of error equal?
Often use decision theory to make decisions from probabilities.
Classification Example | Spam | Not Spam |
Predicted Spam | True Positive | False Positive |
Predicted Not Spam | False Negative | True Negative |
2826097
Demo
Scikit Learn Classification
2826097
Machine Leaning Mechanics – �Terminology and Techniques
Lecture 3
Credit: Joseph E. Gonzalez and Narges Norouzi
Reference Book Chapters: Chapter 1
Homework!
Berkeley's favorite pastime
2826097
Homework Outlines
Part 1: Lecture application
Part 2: Paper implementation
2826097
Homework in the age of AGI
2826097
Downloading Homeworks
2826097
Homework 1
Part 1 - due Sep 19th
Part 2: due Sep26th
2826097
Fun paper about train/test splits
ImageNet
ImageNetV2
ImageNetV2 was collected in the same way as ImageNet but ImageNet models achieve a lower accuracy
∗Authors ordered alphabetically. Ben did none of the work.
visually very similar
2826097
Fun paper about train/test splits
∗Authors ordered alphabetically. Ben did none of the work.
expected
actual
ImageNetV2 was collected in the same way as ImageNet but ImageNet models achieve a lower accuracy
2826097
Have Fun!!!