1. Home
  2. Explore
  3. Computer Science
  4. Multi-Output Linear Prediction

Study methods

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

Multi-Output Linear Prediction

  • 21Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Multiple Inputs and Outputs

How can we handle multiple outputs when there is only one input variable?

21 questions

  1. 1

    How can we handle multiple outputs when there is only one input variable?

    Model answer

    We can use separate linear formulas, one for each output, all using the same input xxx.

    Explanation

    The content states that with one input xxx and multiple outputs y1,y2,y3y_1, y_2, y_3y1​,y2​,y3​, you can have three different formulas g1,g2,g3g_1, g_2, g_3g1​,g2​,g3​ inside the system, each producing one output. This is not a problem because each output gets its own predictor.

  2. 2

    What is the challenge when we have multiple inputs?

    Model answer

    The challenge is handling multiple input variables (features) simultaneously to predict one or more outputs, which requires a matrix representation.

    Explanation

    The content identifies that when there are multiple inputs x1,x2,x3x_1, x_2, x_3x1​,x2​,x3​ and one or more outputs, it is more complicated and is handled using matrices.

  3. 3

    In the context of prediction with multiple inputs, how are the input data structured?

    Model answer

    The input data is structured as a matrix XXX with nnn rows (samples) and ddd columns (features or dimensions).

    Explanation

    The content explains that xxx is a table or matrix, where each row is an input example and each column is a feature. The matrix XXX has nnn rows and ddd columns.

  4. 4

    How are categorical variables like 'married' or occupation handled when creating the input matrix XXX?

    Model answer

    They are converted into numbers (e.g., using categorical encoding) or the columns are dropped.

    Explanation

    The content states that text values are either converted into numbers like categories or the columns are thrown out and not used.

  5. 5

    What does each row in the output matrix YYY represent?

    Model answer

    Each row in YYY represents the output values (predictions or actual targets) corresponding to one input row in XXX.

    Explanation

    The content describes that YYY is a matrix where each row corresponds to a row in XXX, and if there are multiple outputs, there are multiple columns in YYY.

  6. 6

    Why is a column of ones added to the input matrix XXX?

    Model answer

    To incorporate a bias term (y-intercept) in the linear model, so that the prediction includes a constant offset.

    Explanation

    The content explains that the extra column of ones is added so that the model can have the concept of bias or y-intercept. The first element w0w_0w0​ multiplied by 1 becomes the bias.

  7. 7

    In the linear model y=Xwy = Xwy=Xw, what does w0w_0w0​ represent?

    Model answer

    w0w_0w0​ represents the bias or y-intercept term.

    Explanation

    The content says that w0w_0w0​ turns out to be the idea of the y-intercept or bias that the model starts with.

  8. 8

    How is a prediction made for a new input row xnewx_{\text{new}}xnew​ after the model is trained?

    Model answer

    The prediction is computed as ypred=xnew⋅wy_{\text{pred}} = x_{\text{new}} \cdot wypred​=xnew​⋅w, the dot product of the input row (including the leading 1) with the weight vector www.

    Explanation

    The content states that once www is known, taking any new row and multiplying it by www gives the predicted yyy value. The row includes the leading 1 for the bias.

  9. 9

    Write the prediction formula for a single input row with three features (age, years worked, income) using the bias term.

    Model answer

    y^=1⋅w0+age⋅w1+years⋅w2+income⋅w3\hat{y} = 1\cdot w_0 + \text{age}\cdot w_1 + \text{years}\cdot w_2 + \text{income}\cdot w_3y^​=1⋅w0​+age⋅w1​+years⋅w2​+income⋅w3​.

    Explanation

    The content gives the example: 1⋅w0+25⋅w1+3⋅w2+50⋅w31\cdot w_0 + 25\cdot w_1 + 3\cdot w_2 + 50\cdot w_31⋅w0​+25⋅w1​+3⋅w2​+50⋅w3​ for a row with age=25, years=3, income=50.

  10. 10

    Why is squared error used instead of just the error (ypred−yy_{\text{pred}} - yypred​−y)?

    Model answer

    Squared error avoids positive and negative errors canceling each other out, giving a non-negative measure of overall error.

    Explanation

    The content explains that if you use the raw difference, positive and negative errors might cancel, so squaring the error and then taking the average (MSE) is a better measure.

  11. 11

    Define the mean squared error (MSE) in matrix form for linear regression.

    Model answer

    MSE=1n(Xw−y)T(Xw−y)\text{MSE} = \frac{1}{n} (Xw - y)^T (Xw - y)MSE=n1​(Xw−y)T(Xw−y).

    Explanation

    The content shows the formula in summation form and then in matrix form. The top formula in the slide is 1n∥Xw−y∥2\frac{1}{n} \|Xw - y\|^2n1​∥Xw−y∥2 which expands to that.

  12. 12

    How do we find the optimal weight vector www that minimizes the mean squared error?

    Model answer

    We take the gradient of the MSE with respect to www, set it equal to zero, and solve for www.

    Explanation

    The content says: take the derivative (gradient) with respect to www, set it to zero, and solve for www. This leads to the normal equation.

  13. 13

    What is the gradient of the MSE with respect to www?

    Model answer

    ∇wMSE=2nXT(Xw−y)\nabla_w \text{MSE} = \frac{2}{n} X^T (Xw - y)∇w​MSE=n2​XT(Xw−y).

    Explanation

    The content shows the gradient expression: taking the derivative leads to something like XT(Xw−y)X^T(Xw - y)XT(Xw−y) (up to a constant factor). Setting it to zero gives the normal equation.

  14. 14

    Write the normal equation for linear regression.

    Model answer

    w=(XTX)−1XTyw = (X^T X)^{-1} X^T yw=(XTX)−1XTy.

    Explanation

    The content derives the formula: after setting the gradient to zero, you get XTXw=XTyX^T X w = X^T yXTXw=XTy and then solve for www.

  15. 15

    What are the dimensions of (XTX)(X^T X)(XTX) and why is it manageable?

    Model answer

    It is a d×dd \times dd×d matrix, where ddd is the number of features (including bias). This is small even if nnn is large, making it manageable.

    Explanation

    The content explains that XXX is n×dn \times dn×d and XTX^TXT is d×nd \times nd×n, so their product is d×dd \times dd×d. The dimensions collapse to a compact size.

  16. 16

    What are the dimensions of the weight matrix www when there are multiple outputs?

    Model answer

    www is a d×md \times md×m matrix, where ddd is the number of features and mmm is the number of outputs.

    Explanation

    The content states that www dimensions are ddd by mmm. For example, if there are 5 features and 3 outputs, www is 5×35 \times 35×3.

  17. 17

    In the code example, what are the calculated coefficients for the credit score prediction?

    Model answer

    w0=426w_0 = 426w0​=426 (bias), w1=−60w_1 = -60w1​=−60 (age), w2=149w_2 = 149w2​=149 (years with current employer), w3=3.7w_3 = 3.7w3​=3.7 (income in thousands).

    Explanation

    The content lists the coefficients: everyone's credit score has a base of 426, then loses 60 per year of age, gains 149 per year with employer, and gains 3.7 per thousand dollars income.

  18. 18

    How does the library function (e.g., in scikit-learn) handle multiple inputs and multiple outputs?

    Model answer

    It can accept XXX as a matrix with multiple columns and yyy as a matrix with multiple columns, and the code is otherwise the same as for the single-variable case.

    Explanation

    The content states that the library function can take XXX with multiple columns and yyy with multiple columns, and the code is identical.

  19. 19

    Describe the general machine learning framework for prediction presented in the content.

    Model answer

    We have an input xxx (a single value, vector, or matrix) that goes into a function g(x)g(x)g(x) to produce a predicted output YYY. We train on known data to learn g(x)g(x)g(x), then use it to predict on unseen xxx.

    Explanation

    The content summarizes the framework: xxx is input, g(x)g(x)g(x) is the predictor, output is YYY. Training uses data to learn g(x)g(x)g(x), then prediction on new xxx.

  20. 20

    What is the difference between the learned function g(x)g(x)g(x) and the ideal or perfect function f(x)f(x)f(x)?

    Model answer

    f(x)f(x)f(x) is the true unknown function that perfectly gives yyy from xxx, while g(x)g(x)g(x) is an approximation learned from data that we hope is close to f(x)f(x)f(x).

    Explanation

    The content mentions that g(x)g(x)g(x) becomes close enough to the ideal function f(x)f(x)f(x) which would be the perfect predictor.

  21. 21

    What are two methods mentioned for finding or approximating the predictor function g(x)g(x)g(x)?

    Model answer

    Direct calculation (like solving the normal equation for linear regression) and iterative guess-and-check (iteratively adjusting parameters based on error).

    Explanation

    The content says there are cases where we can calculate the best parameters directly (like linear regression) and cases where we can't but can take a good guess and iteratively improve by looking at the error.

1 of 21
Question 1 of 21

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent