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

Speaker 1Speaker 2

Multi-Output Linear Prediction

3:03
0:00-3:03
  1. Corey

    So in the last module we looked at linear prediction with just one input and one output — a single x and a single y. But real problems are never that simple, right?

  2. Simon

    Exactly. We usually have many factors influencing what we want to predict. The good news is we can extend that same linear idea to multiple inputs and even multiple outputs. The first case — one input but multiple outputs — is actually straightforward.

  3. Corey

    Right — you just build a separate formula for each output. Stick one x in, and each formula gives you a different y. But the tricky case is when you have multiple inputs — say, age, years at employer, income — and you want to predict one or more outputs like a credit score.

  4. Simon

    And that's the core of machine learning. We organize our data into a matrix X where each row is a different person, and each column is a feature. Then we have a vector or matrix y of the known outputs. The goal is to find a weight matrix w so that Xw gives us predictions close to the actual y.

  5. Corey

    We also add a column of ones to X. That might seem odd, but it lets us include a bias or y‑intercept term. So if our original features are age, years, and income, the first column is all ones. Then w0 becomes the bias, and w1, w2, w3 are the coefficients for the features.

  6. Simon

    So to find the best w, we need a way to measure error. The standard choice is mean squared error — average of (predicted − actual)². Writing that in matrix form, we want to minimize that error. And we can do that by taking the derivative with respect to w, setting it to zero, and solving.

  7. Corey

    That sounds messy, but the result is the normal equation: w = (XᵀX)⁻¹Xᵀy. Now look at the dimensions. X is n rows by d features, so XᵀX is d×d — that's small if you have only a handful of features. And then Xᵀy is d×m, where m is the number of outputs. So w ends up being d×m — very compact!

  8. Simon

    And it's easy to compute in code. In the lecture they showed a numpy example with the exact numbers from a small table: X had ones, age, years with employer, and income in thousands. y had credit scores. A few lines of code and you get w: bias of 426, then −60 for each year older, 149 for each year with the same employer, and 3.7 per extra thousand dollars.

  9. Corey

    Those numbers come from the training data. They won't give you a perfect prediction in the real world, but they show how w is computed. And once you have w, you can take any new row of features, multiply by w, and get a predicted credit score.

  10. Simon

    That's the machine learning framework in a nutshell. We have input X, we learn a function g(x) — here it's linear — from labeled training data. Then we apply g to new, unseen x to get predictions. Sometimes we can compute the optimal g directly like this; other times we need to iterate, guessing and refining until the error is small enough.

  11. Corey

    And that's what we'll see in future modules. But for now, we've extended linear regression from two variables to many inputs and many outputs. The math looks intimidating, but the core idea — find w that minimizes squared error — is the same as before, just in matrix form.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent