Lecture Introduction and Logistics


Lecture Introduction and Logistics

Michael
Okay, Maria, so today we're tackling the first of three lectures that build up increasingly sophisticated machine learning models. The key idea? It all starts with something you've probably seen before: linear regression. Just fitting a line, but with fancier notation.

Maria
Right, and they mentioned logistics first—there's an Ed thread for in-class questions, and downloadable notes and a template for following along. But the real meat is the structure: linear regression today, then classification next time, and then a generalized exponential family of models that unifies a lot.

Michael
Exactly. And the cool part is that the same optimization workhorse—stochastic gradient descent—appears throughout. So let's start with the basics of supervised learning. We have a hypothesis function h that maps from input space X to output space Y. For example, X could be images and Y could be labels like 'cat' or 'dog'.

Maria
Or text and whether it's hate speech. And we're given a training set of pairs (x_i, y_i). The goal is to find a good h, where 'good' usually means it predicts accurately on new data, not just the training set. That's the whole idea of generalization.

Michael
Right. And they emphasized that if Y is discrete, it's classification; if continuous, it's regression. House price prediction is a classic regression example. They showed real data from Ames, Iowa—plotting square footage versus price, and you can see a rough linear trend.

Maria
So for linear regression, we restrict h to be an affine function: h_θ(x) = θ_0 + θ_1 x_1 + ... + θ_d x_d. To make it linear in the parameters, they set x_0 = 1, so it's really θ^T x with that extra bias term. Then all the parameters are in a vector θ.

Michael
Now we need a way to pick good θ. The cost function they use is the sum of squared errors, with a 1/2 in front to simplify derivatives later. So J(θ) = (1/2) Σ_i (h_θ(x_i) - y_i)^2. Minimizing that gives us the best-fit line.

Maria
And to minimize it, we use gradient descent. Start with an initial guess, compute the gradient of J with respect to θ, then step in the opposite direction. The update is θ^(t+1) = θ^(t) - α ∇J(θ^(t)), where α is the learning rate—a step size you have to pick carefully.

Michael
Too big and you overshoot; too small and you make painfully slow progress. For linear regression, the cost function is convex—bowl-shaped—so gradient descent will find the global minimum. But in modern ML, we often use functions that aren't convex, and we just run until it 'feels good'.

Maria
That's where stochastic gradient descent comes in. Instead of computing the gradient over the entire dataset (which could be billions of points), we estimate it using a small random subset called a mini-batch—or even a single point. That's much faster per step.

Michael
And surprisingly, these noisy updates still converge—there's even a paper called 'Hogwild!' that showed you can run them in crazy parallel ways and they work. Modern frameworks like PyTorch have native mini-batch support. It's the default for a reason.

Maria
They also briefly mentioned the normal equation, which gives a closed-form solution for linear regression, but it's not as scalable. And they touched on overfitting—the idea that if you fit the training data too perfectly, you might not generalize. But modern ML has shown that sometimes interpolation works fine.

Michael
So that's the big picture: we set up supervised learning, defined a cost function, and learned two ways to minimize it—batch gradient descent and stochastic/mini-batch. Next time, we'll generalize this framework to classification and beyond. But for now, we've got the foundation.

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