Lecture Introduction and Logistics
- 29Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Define supervised learning in terms of the training set, hypothesis function, and goal.
29 questions
- 1
Define supervised learning in terms of the training set, hypothesis function, and goal.
Model answer
Supervised learning is given a training set of pairs (xi,yi) and finds a hypothesis h:X→Y that predicts well on new data.
Explanation
The training set provides examples; the hypothesis maps inputs to outputs. The goal is to generalize to unseen examples.
- 2
What is a training set?
Model answer
A training set is a set of n pairs (xi,yi), where xi is an input and yi is its label or target.
Explanation
Each pair is a training example; the set is used to learn the hypothesis.
- 3
What is the hypothesis function h in supervised learning?
Model answer
The hypothesis h is a function h:X→Y that the algorithm learns to predict outputs from inputs.
Explanation
h is chosen from a class of functions, e.g., linear functions, to approximate the true mapping.
- 4
Distinguish between classification and regression.
Model answer
Classification predicts a discrete output Y (e.g., cat/no cat), while regression predicts a continuous output Y (e.g., house price).
Explanation
The type of output space determines whether the problem is classification (discrete) or regression (continuous).
- 5
What is the goal of supervised learning regarding new, unseen data?
Model answer
The goal is to make accurate predictions on new data drawn from the same distribution as the training data, not just to memorize training examples.
Explanation
Generalization to unseen examples is the key objective, which is why we evaluate on test data.
- 6
What is overfitting?
Model answer
Overfitting occurs when a model fits the training data too closely, capturing noise, and performs poorly on new data.
Explanation
It arises from excessively complex models; modern deep learning sometimes defies this trade-off.
- 7
Write the linear regression hypothesis hθ(x) in expanded form for d features.
Model answer
hθ(x)=θ0x0+θ1x1+⋯+θdxd, with x0=1.
Explanation
This is an affine function made linear by the convention that x0=1. The parameters θj are weights.
- 8
Why do we set x0=1 in linear regression?
Model answer
To absorb the bias term θ0 into the linear form, making the hypothesis hθ(x)=∑j=0dθjxj.
Explanation
This simplifies notation by treating the intercept as a weight on a constant feature.
- 9
How many parameters does a linear regression model with d features have?
Model answer
d+1 parameters: θ0,θ1,…,θd.
Explanation
The extra parameter (compared to number of features) is due to the bias term θ0 corresponding to x0=1.
- 10
Represent the training data as a matrix X. What are its dimensions?
Model answer
X is an n×(d+1) matrix, where n is number of training examples and each row contains xi0=1, xi1,…,xid.
Explanation
Each row is a feature vector for one example; the column of ones accounts for the bias.
- 11
What is a feature vector in the context of linear regression?
Model answer
A feature vector is a (d+1)-dimensional vector [1,x1,x2,…,xd]T representing a single training example with the bias term included.
Explanation
Features are the input attributes used to make predictions; the leading 1 is a convention.
- 12
Write the least squares cost function J(θ) for linear regression over n training examples.
Model answer
J(θ)=21∑i=1n(hθ(xi)−yi)2.
Explanation
This sum of squared errors penalizes large deviations; the 21 simplifies derivatives.
- 13
Why is the 21 factor included in the least squares cost function?
Model answer
To cancel the factor of 2 that appears when taking the derivative, simplifying the gradient expression.
Explanation
The minimizer does not depend on constant scaling, so the 21 is a convenience for optimization.
- 14
Interpret the cost function J(θ) in terms of prediction errors.
Model answer
J(θ) measures the total squared difference between predictions hθ(xi) and true labels yi, penalizing larger errors more.
Explanation
Minimizing J encourages predictions to be close to the actual values on the training set.
- 15
For linear regression, is the cost function J(θ) convex? What does that imply about local minima?
Model answer
Yes, J(θ) is convex (bowl-shaped), so any local minimum is also a global minimum, and gradient descent can find the optimal parameters.
Explanation
Convexity ensures a unique global optimum; this is not true for more complex models like neural networks.
- 16
Derive the partial derivative ∂θj∂J(θ) for linear regression.
Model answer
∂θj∂J(θ)=∑i=1n(hθ(xi)−yi)xij, where xij is the j-th feature of the i-th example.
Explanation
The derivative follows from applying the chain rule: the 21 cancels with the 2 from the derivative of the square, and ∂θj∂hθ(xi)=xij.
- 17
Write the batch gradient descent update rule for linear regression parameters θj.
Model answer
θj(t+1)=θj(t)−α∑i=1n(hθ(xi)−yi)xij, where α is the learning rate.
Explanation
This updates each parameter in the direction of steepest descent using all training examples.
- 18
What is the role of the learning rate α in gradient descent?
Model answer
The learning rate controls the step size: how much we adjust parameters in the direction of the negative gradient at each iteration.
Explanation
A proper α ensures convergence; too large can overshoot, too small makes progress slow.
- 19
What happens if the learning rate is too large? Too small?
Model answer
Too large: the algorithm may overshoot the minimum and diverge. Too small: convergence is very slow, requiring many iterations.
Explanation
The ideal α balances speed and stability; practical methods often decay the learning rate over time.
- 20
How do we typically decide when to stop gradient descent?
Model answer
We stop when the update magnitude (e.g., ∥θ(t+1)−θ(t)∥) becomes smaller than a tolerance, or when the cost function stops decreasing significantly.
Explanation
For convex problems, small gradient indicates near-optimum; for non-convex, we often run a fixed number of steps or monitor validation error.
- 21
What is stochastic gradient descent (SGD) and how does it differ from batch gradient descent?
Model answer
SGD uses a single randomly chosen training example per update instead of the entire training set. This makes each step noisy but much faster.
Explanation
SGD can escape shallow local minima and is more efficient for large datasets, though it may never exactly converge.
- 22
What is mini-batch gradient descent?
Model answer
Mini-batch gradient descent uses a small random subset (mini-batch) of B<n examples per update, balancing gradient quality and computational cost.
Explanation
Typical mini-batch sizes are 32–256; modern hardware processes mini-batches efficiently in parallel.
- 23
How does batch size affect the gradient estimate and computational cost?
Model answer
Larger batch size gives a more accurate gradient estimate but requires more computation per update. Smaller batches are noisier but allow more frequent updates.
Explanation
There is a trade-off: mini-batches offer a practical compromise, often with diminishing returns beyond a certain size.
- 24
Why is mini-batch gradient descent commonly used in modern machine learning?
Model answer
Mini-batching leverages parallel hardware (GPUs) to process multiple examples simultaneously, reduces noise compared to SGD, and avoids the high cost of full-batch updates on large datasets.
Explanation
It provides a good balance of efficiency and convergence stability, and is supported natively in frameworks like PyTorch and TensorFlow.
- 25
What is the normal equation for linear regression?
Model answer
The normal equation is θ=(XTX)−1XTy, which gives the closed-form solution that minimizes the least squares cost.
Explanation
It avoids iterative gradient descent but requires inverting a (d+1)×(d+1) matrix, which is costly for large d.
- 26
For a convex cost function like linear regression’s, why does gradient descent converge to the global minimum?
Model answer
Convex functions have no local minima other than the global minimum, and gradient descent follows the gradient to the unique optimum (with appropriate learning rate).
Explanation
The bowl-shaped surface ensures that any downhill direction leads to the same bottom; this property fails for non-convex models.
- 27
Explain the trade-off between using a large or small learning rate in practice.
Model answer
A large learning rate speeds up initial progress but risks divergence; a small learning rate is stable but slow. Users often decay the learning rate or use adaptive methods.
Explanation
The optimal learning rate depends on the problem; common heuristics include a constant small value or scheduling (e.g., step decay).
- 28
How does overfitting relate to training error vs. test error?
Model answer
Overfitting occurs when training error is low but test error is high, because the model has learned noise specific to the training set rather than general patterns.
Explanation
Regularization and validation are used to mitigate overfitting; modern models sometimes interpolate data yet generalize well.
- 29
What is the hypothesis class in linear regression?
Model answer
The hypothesis class is the set of all linear (affine) functions parameterized by θ, i.e., hθ(x)=θTx with x0=1.
Explanation
This restriction from all possible functions makes the problem tractable; the number of parameters d+1 determines model complexity.

Ask anything
We've read this whole study set, so questions about it get the best answers.