Multi-Output Linear Prediction
- 21Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
How can we handle multiple outputs when there is only one input variable?
21 questions
- 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 x.
Explanation
The content states that with one input x and multiple outputs y1,y2,y3, you can have three different formulas g1,g2,g3 inside the system, each producing one output. This is not a problem because each output gets its own predictor.
- 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,x3 and one or more outputs, it is more complicated and is handled using matrices.
- 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 X with n rows (samples) and d columns (features or dimensions).
Explanation
The content explains that x is a table or matrix, where each row is an input example and each column is a feature. The matrix X has n rows and d columns.
- 4
How are categorical variables like 'married' or occupation handled when creating the input matrix X?
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
What does each row in the output matrix Y represent?
Model answer
Each row in Y represents the output values (predictions or actual targets) corresponding to one input row in X.
Explanation
The content describes that Y is a matrix where each row corresponds to a row in X, and if there are multiple outputs, there are multiple columns in Y.
- 6
Why is a column of ones added to the input matrix X?
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 w0 multiplied by 1 becomes the bias.
- 7
In the linear model y=Xw, what does w0 represent?
Model answer
w0 represents the bias or y-intercept term.
Explanation
The content says that w0 turns out to be the idea of the y-intercept or bias that the model starts with.
- 8
How is a prediction made for a new input row xnew after the model is trained?
Model answer
The prediction is computed as ypred=xnew⋅w, the dot product of the input row (including the leading 1) with the weight vector w.
Explanation
The content states that once w is known, taking any new row and multiplying it by w gives the predicted y value. The row includes the leading 1 for the bias.
- 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.
Explanation
The content gives the example: 1⋅w0+25⋅w1+3⋅w2+50⋅w3 for a row with age=25, years=3, income=50.
- 10
Why is squared error used instead of just the error (ypred−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
Define the mean squared error (MSE) in matrix form for linear regression.
Model answer
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 n1∥Xw−y∥2 which expands to that.
- 12
How do we find the optimal weight vector w that minimizes the mean squared error?
Model answer
We take the gradient of the MSE with respect to w, set it equal to zero, and solve for w.
Explanation
The content says: take the derivative (gradient) with respect to w, set it to zero, and solve for w. This leads to the normal equation.
- 13
What is the gradient of the MSE with respect to w?
Model answer
∇wMSE=n2XT(Xw−y).
Explanation
The content shows the gradient expression: taking the derivative leads to something like XT(Xw−y) (up to a constant factor). Setting it to zero gives the normal equation.
- 14
Write the normal equation for linear regression.
Model answer
w=(XTX)−1XTy.
Explanation
The content derives the formula: after setting the gradient to zero, you get XTXw=XTy and then solve for w.
- 15
What are the dimensions of (XTX) and why is it manageable?
Model answer
It is a d×d matrix, where d is the number of features (including bias). This is small even if n is large, making it manageable.
Explanation
The content explains that X is n×d and XT is d×n, so their product is d×d. The dimensions collapse to a compact size.
- 16
What are the dimensions of the weight matrix w when there are multiple outputs?
Model answer
w is a d×m matrix, where d is the number of features and m is the number of outputs.
Explanation
The content states that w dimensions are d by m. For example, if there are 5 features and 3 outputs, w is 5×3.
- 17
In the code example, what are the calculated coefficients for the credit score prediction?
Model answer
w0=426 (bias), w1=−60 (age), w2=149 (years with current employer), w3=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
How does the library function (e.g., in scikit-learn) handle multiple inputs and multiple outputs?
Model answer
It can accept X as a matrix with multiple columns and y 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 X with multiple columns and y with multiple columns, and the code is identical.
- 19
Describe the general machine learning framework for prediction presented in the content.
Model answer
We have an input x (a single value, vector, or matrix) that goes into a function g(x) to produce a predicted output Y. We train on known data to learn g(x), then use it to predict on unseen x.
Explanation
The content summarizes the framework: x is input, g(x) is the predictor, output is Y. Training uses data to learn g(x), then prediction on new x.
- 20
What is the difference between the learned function g(x) and the ideal or perfect function f(x)?
Model answer
f(x) is the true unknown function that perfectly gives y from x, while g(x) is an approximation learned from data that we hope is close to f(x).
Explanation
The content mentions that g(x) becomes close enough to the ideal function f(x) which would be the perfect predictor.
- 21
What are two methods mentioned for finding or approximating the predictor function 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.

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