Linear Regression Introduction
- 37Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What distinguishes a supervised learning regression problem from a classification problem?
What distinguishes a supervised learning regression problem from a classification problem?
37 questions
- 1
What distinguishes a supervised learning regression problem from a classification problem?
- A
Regression uses labeled data, while classification uses unlabeled data.
- B
The input features are continuous for regression, and discrete for classification.
- C
The output variable is continuous for regression, and categorical for classification.
- D
Regression requires a linear hypothesis, while classification requires a nonlinear hypothesis.
Correct answer
CThe output variable is continuous for regression, and categorical for classification.
Explanation
In supervised learning, regression predicts continuous values (e.g., price), while classification predicts discrete labels (e.g., category).
- A
- 2
In the linear regression hypothesis hθ(x)=θ0+θ1x, what is the role of θ0?
- A
It is the slope of the line.
- B
It is the weight for the feature x.
- C
It is the intercept term, allowing the hypothesis to fit data not passing through the origin.
- D
It represents the input feature value.
Correct answer
CIt is the intercept term, allowing the hypothesis to fit data not passing through the origin.
Explanation
θ0 is the bias term (intercept), making the hypothesis an affine function, not necessarily linear through the origin.
- A
- 3
In linear regression with multiple features, how is the hypothesis expressed using summation notation?
- A
hθ(x)=∑j=1nθjxj.
- B
hθ(x)=∑j=0nθjxj, where x0=1.
- C
hθ(x)=∑i=1mθixi.
- D
hθ(x)=∑j=0nθjxj, where θ0=1.
Correct answer
Bhθ(x)=∑j=0nθjxj, where x0=1.
Explanation
The hypothesis is ∑j=0nθjxj with x0=1 to include the intercept term conveniently.
- A
- 4
What do m and n represent in the context of linear regression?
- A
m is the number of features, and n is the number of training examples.
- B
m is the number of parameters, and n is the number of iterations.
- C
m is the number of output variables, and n is the number of input variables.
- D
m is the number of training examples, and n is the number of features.
Correct answer
Dm is the number of training examples, and n is the number of features.
Explanation
Standard notation: m = number of training examples, n = number of features.
- A
- 5
How is the cost function J(θ) defined for linear regression?
- A
J(θ)=m1∑i=1m(hθ(x(i))−y(i))4
- B
J(θ)=2m1∑i=1m(hθ(x(i))−y(i))2
- C
J(θ)=21∑i=1m(hθ(x(i))−y(i))
- D
J(θ)=m1∑i=1m∣hθ(x(i))−y(i)∣
Correct answer
BJ(θ)=2m1∑i=1m(hθ(x(i))−y(i))2
Explanation
The cost function is half of the average squared error, simplifying derivative calculations.
- A
- 6
Why is the factor 21 included in the cost function J(θ)?
- A
To scale the gradient so that it fits within numerical precision.
- B
To make the cost function independent of the number of training examples.
- C
To cancel the factor of 2 that appears when taking the derivative of square terms.
- D
To ensure the cost function is convex.
Correct answer
CTo cancel the factor of 2 that appears when taking the derivative of square terms.
Explanation
The 21 cancels the 2 from the derivative of (h−y)2, simplifying gradient expressions.
- A
- 7
In batch gradient descent, how is the parameter θj updated?
- A
θj:=θj−αm1∑i=1m(hθ(x(i))−y(i))xj(i)
- B
θj:=θj−α2m1∑i=1m(hθ(x(i))−y(i))xj(i)
- C
θj:=θj−αm1∑i=1m(hθ(x(i))−y(i))2
- D
θj:=θj−α(hθ(x(j))−y(j))xj(j)
Correct answer
Aθj:=θj−αm1∑i=1m(hθ(x(i))−y(i))xj(i)
Explanation
Batch gradient descent uses the average gradient over all training examples.
- A
- 8
What is the main disadvantage of batch gradient descent?
- A
It cannot be used with a squared error cost function.
- B
Each iteration requires scanning the entire training set, which is slow for large datasets.
- C
It converges to a local minimum instead of the global minimum.
- D
It requires the learning rate to be exactly 0.01.
Correct answer
BEach iteration requires scanning the entire training set, which is slow for large datasets.
Explanation
Batch GD sums over all m examples per step, making it computationally expensive for large m.
- A
- 9
How does stochastic gradient descent (SGD) differ from batch gradient descent?
- A
SGD always converges exactly to the global minimum, while batch GD may not.
- B
SGD is only applicable to linear regression, while batch GD works for any model.
- C
SGD updates parameters using one training example at a time, while batch GD uses the entire dataset.
- D
SGD uses a larger learning rate than batch GD.
Correct answer
CSGD updates parameters using one training example at a time, while batch GD uses the entire dataset.
Explanation
SGD performs an update for each individual example, making it faster per iteration but with noisy convergence.
- A
- 10
What is a typical convergence behavior of stochastic gradient descent?
- A
It will oscillate around the minimum and never perfectly converge, but often gets close.
- B
It converges exactly to the global minimum after one pass through the data.
- C
It diverges unless the learning rate is decreased over time.
- D
It converges faster than batch GD but requires second-order information.
Correct answer
AIt will oscillate around the minimum and never perfectly converge, but often gets close.
Explanation
SGD's updates are noisy, so it bounces around the minimum; decreasing learning rate helps it settle closer.
- A
- 11
When is batch gradient descent preferred over stochastic gradient descent?
- A
When the dataset is small (e.g., hundreds to thousands of examples) and computational cost is acceptable.
- B
When the dataset is very large (millions of examples) to ensure convergence.
- C
When the learning rate needs to be selected automatically.
- D
When the cost function is not convex.
Correct answer
AWhen the dataset is small (e.g., hundreds to thousands of examples) and computational cost is acceptable.
Explanation
For small datasets, batch GD is simpler and avoids tuning for noisy convergence; for large datasets, SGD is more efficient.
- A
- 12
In the derivation of the normal equations, what is the design matrix X?
- A
A matrix where each column is a training example feature vector x(i).
- B
A matrix containing the target values y(i).
- C
A matrix where the first column is all ones and the remaining columns are feature values.
- D
A matrix where each row is the transpose of a training example feature vector x(i).
Correct answer
DA matrix where each row is the transpose of a training example feature vector x(i).
Explanation
The design matrix X is m×(n+1) with rows (x(i))T, used to compute Xθ as predictions.
- A
- 13
What is the normal equation solution for the optimal θ in linear regression?
- A
θ=(XTX)−1XTy
- B
θ=X−1y
- C
θ=(XTX)XTy
- D
θ=XT(XXT)−1y
Correct answer
Aθ=(XTX)−1XTy
Explanation
By setting the derivative of J(θ) to zero, we obtain XTXθ=XTy, leading to θ=(XTX)−1XTy if XTX is invertible.
- A
- 14
What does it mean if XTX is non-invertible?
- A
The cost function is not convex.
- B
The features are linearly dependent (redundant), e.g., duplicate or collinear features.
- C
Gradient descent will not work.
- D
The number of training examples is less than the number of features.
Correct answer
BThe features are linearly dependent (redundant), e.g., duplicate or collinear features.
Explanation
Non-invertibility often indicates redundant features; using the pseudo-inverse can still yield a solution, but it's better to remove redundant features.
- A
- 15
What is the trace of a square matrix A?
- A
The sum of its diagonal entries.
- B
The product of its diagonal entries.
- C
The sum of all entries of A.
- D
The determinant of A.
Correct answer
AThe sum of its diagonal entries.
Explanation
The trace tr(A)=∑iAii.
- A
- 16
Which property of the trace operator is used in deriving the normal equations?
- A
tr(A+B)=tr(A)+tr(B)
- B
tr(A−1)=1/tr(A)
- C
tr(AB)=tr(BA)
- D
tr(AT)=tr(A)
Correct answer
Ctr(AB)=tr(BA)
Explanation
The cyclic permutation property tr(AB)=tr(BA) is used when differentiating the quadratic form.
- A
- 17
In the gradient descent update for linear regression, what is the partial derivative of J(θ) with respect to θj for a single training example (x,y)?
- A
(y−hθ(x))
- B
(hθ(x)−y)xj
- C
(hθ(x)−y)2xj
- D
21(hθ(x)−y)xj
Correct answer
B(hθ(x)−y)xj
Explanation
For one example, the derivative is (hθ(x)−y)⋅xj, derived from the chain rule.
- A
- 18
What is a common default value for the learning rate α in gradient descent?
- A
0.001
- B
0.01
- C
0.1
- D
1.0
Correct answer
B0.01
Explanation
A typical starting point for α is 0.01, often adjusted on an exponential scale.
- A
- 19
Why is the learning rate α important in gradient descent?
- A
It affects the convexity of the cost function.
- B
It must be set to 1 to ensure convergence.
- C
It controls the step size; too large can overshoot the minimum, too small slows convergence.
- D
It determines the number of iterations needed to converge exactly.
Correct answer
CIt controls the step size; too large can overshoot the minimum, too small slows convergence.
Explanation
The learning rate governs the magnitude of parameter updates; proper tuning is essential for efficient convergence.
- A
- 20
In the transcript, what example dataset is used to illustrate linear regression?
- A
Stock prices from New York Stock Exchange.
- B
Self-driving car steering angles from the ALVINN project.
- C
Census data from the United States.
- D
Housing prices from Portland, Oregon based on size and number of bedrooms.
Correct answer
DHousing prices from Portland, Oregon based on size and number of bedrooms.
Explanation
The instructor uses a dataset of house sizes and prices from Portland, Oregon, collected from Craigslist.
- A
- 21
According to the lecture, what is the job of a learning algorithm in supervised learning?
- A
To output a hypothesis function that maps inputs to outputs.
- B
To compute the average of all output values.
- C
To store all training examples in memory for prediction.
- D
To find the maximum likelihood estimate of the parameters.
Correct answer
ATo output a hypothesis function that maps inputs to outputs.
Explanation
The learning algorithm processes the training set to produce a hypothesis that makes predictions on new inputs.
- A
- 22
What notation is used to denote the i-th training example's input features?
- A
xi
- B
xi
- C
x(i)
- D
x(i)
Correct answer
Dx(i)
Explanation
The superscript (i) indexes training examples, e.g., x(i) and y(i).
- A
- 23
In the hypothesis hθ(x)=θTx with x0=1, what is the dimensionality of θ if there are n features?
- A
m
- B
n
- C
n−1
- D
n+1
Correct answer
Dn+1
Explanation
With n features plus the intercept, θ is (n+1)-dimensional.
- A
- 24
When running gradient descent, what does it indicate if the cost function J(θ) increases instead of decreases?
- A
The learning rate is too large, causing overshooting.
- B
The algorithm has converged to a local maximum.
- C
The cost function is not convex.
- D
The learning rate is too small.
Correct answer
AThe learning rate is too large, causing overshooting.
Explanation
An increasing cost suggests that the steps are too large, overshooting the minimum.
- A
- 25
What is the main advantage of stochastic gradient descent over batch gradient descent for large datasets?
- A
It can make progress after processing a single example, without waiting for the entire dataset.
- B
It does not require a learning rate.
- C
It guarantees convergence to the global minimum in fewer total operations.
- D
It works with non-differentiable cost functions.
Correct answer
AIt can make progress after processing a single example, without waiting for the entire dataset.
Explanation
SGD updates parameters per example, enabling faster initial progress and feasibility for large datasets.
- A
- 26
In the normal equation derivation, which matrix derivative identity is used to differentiate θTXTXθ?
- A
∇θ(θTAθ)=θTA
- B
∇θ(θTAθ)=2Aθ for symmetric A
- C
∇θ(θTAθ)=Aθ
- D
∇θ(θTAθ)=2θTA
Correct answer
B∇θ(θTAθ)=2Aθ for symmetric A
Explanation
With A=XTX symmetric, the derivative is 2XTXθ.
- A
- 27
What is the 'inverted' technique to help stochastic gradient descent converge closer to the minimum?
- A
Gradually decreasing the learning rate over time.
- B
Increasing the learning rate over time.
- C
Using batch gradient descent after SGD.
- D
Initializing parameters to zero.
Correct answer
AGradually decreasing the learning rate over time.
Explanation
Decreasing the learning rate reduces the oscillation magnitude, allowing SGD to settle nearer the optimum.
- A
- 28
In the lecture, what is the relationship between the trace operator and matrix derivatives?
- A
The derivative of tr(AB) with respect to A is BT.
- B
The derivative of tr(A2) is 2A.
- C
All of the above are used.
- D
The derivative of tr(A) with respect to A is the identity matrix.
Correct answer
AThe derivative of tr(AB) with respect to A is BT.
Explanation
One key property is ∇Atr(AB)=BT, used in the normal equation derivation.
- A
- 29
What is the significance of the ALVINN video mentioned in the lecture?
- A
It showed reinforcement learning for obstacle avoidance.
- B
It was an example of a supervised learning regression problem for self-driving cars.
- C
It introduced the concept of a neural network.
- D
It demonstrated unsupervised learning for lane detection.
Correct answer
BIt was an example of a supervised learning regression problem for self-driving cars.
Explanation
ALVINN used supervised learning to map camera images to steering directions, a regression problem.
- A
- 30
If X is the design matrix of size m×(n+1) and y is m×1, what is the dimension of XTX?
- A
m×(n+1)
- B
(n+1)×(n+1)
- C
m×m
- D
(n+1)×m
Correct answer
B(n+1)×(n+1)
Explanation
XT is (n+1)×m, so XTX is (n+1)×(n+1).
- A
- 31
In the context of gradient descent, what does 'batch' refer to?
- A
Using no training examples and only the cost function.
- B
Using a subset of training examples in one update.
- C
Using all training examples in one update.
- D
Using one training example in one update.
Correct answer
CUsing all training examples in one update.
Explanation
Batch gradient descent processes the entire dataset (the whole batch) per iteration.
- A
- 32
According to the lecturer, what is a common approach to choosing the learning rate?
- A
Derive it analytically from the cost function.
- B
Use a line search for each iteration.
- C
Always set it to 0.01 regardless of the dataset.
- D
Try values on an exponential scale (e.g., 0.01, 0.02, 0.04, 0.08) and select the one that minimizes cost quickly.
Correct answer
DTry values on an exponential scale (e.g., 0.01, 0.02, 0.04, 0.08) and select the one that minimizes cost quickly.
Explanation
The lecturer suggests trying exponentially spaced values to find an effective learning rate.
- A
- 33
What is the term for a matrix where rows are training examples transposed?
- A
Design matrix
- B
Covariance matrix
- C
Gram matrix
- D
Feature matrix
Correct answer
ADesign matrix
Explanation
The design matrix X has each row as (x(i))T.
- A
- 34
In the linear regression cost function, what is the effect of using the sum of squared errors rather than absolute errors?
- A
It penalizes larger errors more heavily.
- B
All of the above.
- C
It always yields a convex optimization problem.
- D
It corresponds to assuming Gaussian noise in the target variable.
Correct answer
BAll of the above.
Explanation
Squared error leads to a convex problem, penalizes outliers more, and relates to Gaussian noise (as mentioned for later lectures).
- A
- 35
What does the lecturer suggest if XTX is non-invertible?
- A
Switch to gradient descent.
- B
Set θ to zero.
- C
Check for redundant features and remove them, or use the pseudo-inverse.
- D
Add more training examples.
Correct answer
CCheck for redundant features and remove them, or use the pseudo-inverse.
Explanation
Non-invertibility often indicates linearly dependent features; fixing that or using pseudo-inverse is recommended.
- A
- 36
In the lecture, what was the number of training examples in the Portland housing dataset?
- A
47
- B
49
- C
100
- D
50
Correct answer
B49
Explanation
The dataset had 49 points (m=49).
- A
- 37
What is the main takeaway from the contour plot of the cost function for linear regression?
- A
The cost function is not convex.
- B
Gradient descent cannot find the global minimum.
- C
The cost function is convex with a single global minimum.
- D
The cost function has many local minima.
Correct answer
CThe cost function is convex with a single global minimum.
Explanation
For linear regression with squared error, J(θ) is convex (bowl-shaped) with one global minimum.
- A

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