1. Home
  2. Explore
  3. Computer Science
  4. Linear Regression Introduction

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Linear Regression Introduction

  • 42Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Supervised Learning Basics
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is supervised learning?

Tap to flipClick to flipspace

A learning problem where you are given input-output pairs (X, Y) and the algorithm learns a mapping from X to Y.

Or swipe the card

42 cards

  1. What is supervised learning?

    A learning problem where you are given input-output pairs (X, Y) and the algorithm learns a mapping from X to Y.

  2. What is the difference between a regression problem and a classification problem?

    Regression predicts a continuous-valued output (e.g., price). Classification predicts a discrete output (e.g., speed category).

  3. In the ALVINN self-driving car example, what type of supervised learning problem was it?

    It was a regression problem, because the output Y (steering direction) is a continuous value.

  4. What is the hypothesis in the context of supervised learning?

    The hypothesis h is a function that maps input features X to an estimated output Y, output by the learning algorithm.

  5. What is a training example in supervised learning?

    A training example is a pair (x, y) where x is the input features and y is the target value.

  6. In linear regression with one input feature, what is the form of the hypothesis?

    h(x)=θ0+θ1xh(x) = \theta_0 + \theta_1 xh(x)=θ0​+θ1​x

  7. How is the hypothesis written for multiple features?

    h(x)=θ0+θ1x1+θ2x2+⋯+θnxnh(x) = \theta_0 + \theta_1 x_1 + \theta_2 x_2 + \dots + \theta_n x_nh(x)=θ0​+θ1​x1​+θ2​x2​+⋯+θn​xn​

  8. What is the purpose of introducing x0=1x_0 = 1x0​=1?

    To write the hypothesis compactly as h(x)=∑j=0nθjxjh(x) = \sum_{j=0}^n \theta_j x_jh(x)=∑j=0n​θj​xj​.

  9. Define the parameters Θ\ThetaΘ in linear regression.

    The parameters Θ\ThetaΘ are the coefficients θ0,θ1,…,θn\theta_0, \theta_1, \dots, \theta_nθ0​,θ1​,…,θn​ that define the hypothesis.

  10. What do MMM, nnn, and the superscript (i)(i)(i) denote in notation?

    MMM is the number of training examples. nnn is the number of features. The superscript (i)(i)(i) indexes the iii-th training example (e.g., x(i)x^{(i)}x(i)).

  11. What is a feature in the context of linear regression?

    A feature is an input attribute used to predict the output; e.g., size of house or number of bedrooms.

  12. Write the hypothesis in vector form for multiple features.

    h(x)=θTxh(x) = \theta^T xh(x)=θTx where θ\thetaθ and xxx are (n+1)(n+1)(n+1)-dimensional vectors (including x0=1x_0=1x0​=1).

  13. What is the design matrix XXX in linear regression?

    The design matrix XXX has rows corresponding to training examples: each row is (x(i))T(x^{(i)})^T(x(i))T, an (n+1)(n+1)(n+1)-dimensional vector. It is of size m×(n+1)m \times (n+1)m×(n+1).

  14. What is the cost function J(θ)J(\theta)J(θ) for linear regression (ordinary least squares)?

    J(θ)=12m∑i=1m(h(x(i))−y(i))2J(\theta) = \frac{1}{2m} \sum_{i=1}^{m} (h(x^{(i)}) - y^{(i)})^2J(θ)=2m1​∑i=1m​(h(x(i))−y(i))2

  15. Why is the 1/21/21/2 term included in the cost function?

    To simplify the derivative calculation; the 1/21/21/2 cancels the factor 222 that appears when differentiating the square.

  16. What is the goal of the cost function in linear regression?

    To choose parameters θ\thetaθ that minimize J(θ)J(\theta)J(θ), making predictions close to the actual values.

  17. Why is squared error often used instead of absolute error?

    The lecture mentions that a probabilistic justification (Gaussian noise assumption) underlies squared error, which will be covered later (GLMs).

  18. What is gradient descent?

    An iterative optimization algorithm that updates parameters in the direction of the negative gradient to minimize a cost function.

  19. Write the gradient descent update rule for a single parameter θj\theta_jθj​ in linear regression.

    θj:=θj−α∂∂θjJ(θ)\theta_j := \theta_j - \alpha \frac{\partial}{\partial \theta_j} J(\theta)θj​:=θj​−α∂θj​∂​J(θ)

  20. What is the gradient descent update for linear regression using all training examples (batch)?

    θj:=θj−α1m∑i=1m(h(x(i))−y(i))xj(i)\theta_j := \theta_j - \alpha \frac{1}{m} \sum_{i=1}^{m} (h(x^{(i)}) - y^{(i)}) x_j^{(i)}θj​:=θj​−αm1​∑i=1m​(h(x(i))−y(i))xj(i)​

  21. What is the role of the learning rate α\alphaα in gradient descent?

    It controls the step size: too large may overshoot the minimum, too small slows convergence.

  22. Why does gradient descent for linear regression not suffer from local minima?

    Because the cost function J(θ)J(\theta)J(θ) for linear regression is convex (a quadratic bowl shape), so any local minimum is global.

  23. What is batch gradient descent?

    A version of gradient descent that uses the entire training set to compute the gradient at each iteration.

  24. What is a disadvantage of batch gradient descent?

    It is computationally expensive for large datasets because each update requires scanning all mmm examples.

  25. What is stochastic gradient descent (SGD)?

    An iterative algorithm that updates parameters using one training example at a time, looping through examples randomly.

  26. Write the SGD update rule for linear regression.

    For each training example iii: θj:=θj−α(h(x(i))−y(i))xj(i)\theta_j := \theta_j - \alpha (h(x^{(i)}) - y^{(i)}) x_j^{(i)}θj​:=θj​−α(h(x(i))−y(i))xj(i)​ for all jjj.

  27. How does the convergence behavior of SGD differ from batch gradient descent?

    SGD is noisy and oscillates; it never exactly converges but typically reaches a good solution faster for large datasets.

  28. When is stochastic gradient descent preferred over batch gradient descent?

    When the dataset is very large (e.g., millions of examples) because SGD makes faster progress per iteration.

  29. How can the performance of SGD be improved?

    By gradually decreasing the learning rate over time, which reduces oscillations and helps converge closer to the minimum.

  30. What is mini-batch gradient descent?

    A compromise between batch and stochastic: uses a small batch of training examples (e.g., 100) per update instead of 1 or all.

  31. What is the normal equation?

    A closed-form solution for θ\thetaθ that minimizes J(θ)J(\theta)J(θ): θ=(XTX)−1XTy\theta = (X^T X)^{-1} X^T yθ=(XTX)−1XTy.

  32. Write the normal equation.

    θ=(XTX)−1XTy\theta = (X^T X)^{-1} X^T yθ=(XTX)−1XTy

  33. What does the normal equation achieve?

    It finds the global minimum of the cost function J(θ)J(\theta)J(θ) in one step, without iterative updates.

  34. What is the vector yyy in the normal equation?

    An mmm-dimensional column vector containing all target values y(i)y^{(i)}y(i) from the training set.

  35. When might XTXX^T XXTX be non-invertible, and what is the remedy?

    Non-invertibility occurs when features are linearly dependent (redundant). The pseudo-inverse can be used, but it's better to identify and remove redundant features.

  36. What is an advantage of the normal equation over gradient descent?

    It does not require choosing a learning rate or iterating; it directly gives the optimal θ\thetaθ.

  37. State the trace of a matrix AAA.

    tr(A)=∑iAii\mathrm{tr}(A) = \sum_i A_{ii}tr(A)=∑i​Aii​ (sum of diagonal entries).

  38. What is the derivative of tr(AB)\mathrm{tr}(AB)tr(AB) with respect to AAA?

    ∂∂Atr(AB)=BT\frac{\partial}{\partial A} \mathrm{tr}(AB) = B^T∂A∂​tr(AB)=BT

  39. State the cyclic property of trace: tr(ABC)=?\mathrm{tr}(ABC) = ?tr(ABC)=?

    tr(ABC)=tr(CAB)=tr(BCA)\mathrm{tr}(ABC) = \mathrm{tr}(CAB) = \mathrm{tr}(BCA)tr(ABC)=tr(CAB)=tr(BCA)

  40. How is the cost function J(θ)J(\theta)J(θ) expressed in matrix form?

    J(θ)=12(Xθ−y)T(Xθ−y)J(\theta) = \frac{1}{2} (X\theta - y)^T (X\theta - y)J(θ)=21​(Xθ−y)T(Xθ−y)

  41. What is the derivative of J(θ)=12(Xθ−y)T(Xθ−y)J(\theta) = \frac{1}{2} (X\theta - y)^T (X\theta - y)J(θ)=21​(Xθ−y)T(Xθ−y) with respect to θ\thetaθ?

    ∂J∂θ=XTXθ−XTy\frac{\partial J}{\partial \theta} = X^T X \theta - X^T y∂θ∂J​=XTXθ−XTy

  42. Derive the normal equation from setting the derivative to zero.

    Set XTXθ−XTy=0X^T X \theta - X^T y = 0XTXθ−XTy=0, then XTXθ=XTyX^T X \theta = X^T yXTXθ=XTy, so θ=(XTX)−1XTy\theta = (X^T X)^{-1} X^T yθ=(XTX)−1XTy.

Card 1 of 42
Card 1 of 42

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent