












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Artificial Intelligence. Lectures Transcriptions of Machine Learning 2007/2008. Lesson 4 - Prof. Andrew Ng - Stanford University
Typology: Study notes
1 / 20
This page cannot be seen from the preview
Don't miss anything!













MachineLearning-Lecture
Instructor (Andrew Ng) :Okay, good morning. Just a few administrative announcements before we jump into today’s technical material. So let’s see, by later today, I’ll post on the course website a handout with the sort of guidelines and suggestions for choosing and proposing class projects.
So project proposals – so for the term project for this class due on Friday, the 19th of this month at noon – that’s about two weeks, two and a half weeks from now. If you haven’t yet formed teams or started thinking about project ideas, please do so.
And later today, you’ll find on the course website a handout with the guidelines and some of the details on how to send me your proposals and so on.
If you’re not sure whether an idea you have for a project may be a appropriate, or you’re sort of just fishing around for ideas or looking for ideas of projects to do, please, be strongly encouraged to come to my office hours on Friday mornings, or go to any of the TA’s office hours to tell us about your project ideas, and we can help brainstorm with you.
I also have a list of project ideas that I sort of collected from my colleagues and from various senior PhD students working with me or with other professors. And so if you want to hear about some of those ideas in topics like on natural [inaudible], computer vision, neuroscience, robotics, control. So [inaudible] ideas and a variety of topics at these, so if you’re having trouble coming up with your own project idea, come to my office hours or to TA’s office hours to ask us for suggestions, to brainstorm ideas with us.
Also, in the previous class I mentioned that we’ll invite you to become [inaudible] with 229, which I think is a fun and educational thing to do. So later today, I’ll also email everyone registered in this class with some of the logistical details about applying to be [inaudible]. So if you’d like to apply to be [inaudible], and I definitely encourage you to sort of consider doing so, please respond to that email, which you’ll get later today.
And finally, problem set one will also be posted online shortly, and will be due in two weeks time, so you can also get that online.
Oh, and if you would like to be [inaudible], please try to submit problem set one on time and not use late days for problem set one because usually select [inaudible] is based on problem set one solutions. Questions for any of that?
Okay, so welcome back. And what I want to do today is talk about new test methods [inaudible] for fitting models like logistic regression, and then we’ll talk about exponential family distributions and generalized linear models. It’s a very nice class of ideas that will tie together, the logistic regression and the ordinary V squares models that we’ll see. So hopefully I’ll get to that today.
So throughout the previous lecture and this lecture, we’re starting to use increasingly large amounts of material on probability. So if you’d like to see a refresher on sort of the foundations of probability – if you’re not sure if you quite had your prerequisites for this class in terms of a background in probability and statistics, then the discussion section taught this week by the TA’s will go over so they can review a probability.
At the same discussion sections also for the TA’s, we’ll also briefly go over sort of [inaudible] octave notation, which you need to use for your problem sets. And so if you any of you want to see a review of the probability and statistics pre-reqs, or if you want to [inaudible] octave, please come to this – the next discussion section.
All right. So just to recap briefly, towards the end of the last lecture I talked about the logistic regression model where we had – which was an algorithm for [inaudible]. We had that [inaudible] of [inaudible] – if an X – if Y equals one, give an X [inaudible] by theta under this model, all right. If this was one over one [inaudible] theta, transpose X. And then you can write down the log like we heard – like given the training sets, which was that.
And by taking the riveters of this, you can derive sort of a gradient ascent interval for finding the maximum likelihood estimate of the parameter stated for this logistic regression model.
And so last time I wrote down the learning rule for [inaudible], but the [inaudible] has to be gradient ascent where you look at just one training example at a time, would be like this, okay. So last time I wrote down [inaudible] gradient ascent. This is still [inaudible] gradient ascent.
So if you want to favor a logistic regression model, meaning find the value of theta that maximizes this log likelihood, gradient ascent or [inaudible] gradient ascent or [inaudible] gradient ascent is a perfectly fine algorithm to use.
But what I want to do is talk about a different algorithm for fitting models like logistic regression. And this would be an algorithm that will, I guess, often run much faster than gradient ascent.
And this algorithm is called Newton’s Method. And when we describe Newton’s Method
Let’s start the [inaudible], and then we’ll sort of slowly change this until it becomes an algorithm for fitting mass and likelihood models, like [inaudible] reduction.
So – let’s see. I guess that works. Okay, so let’s say that’s my function F. This is my horizontal axis of [inaudible] of theta, and so they’re really trying to find this value for theta, and which F of theta is equal to zero. This is a horizontal axis.
Because to maximize this function, we just let F be equal to L prime. Let F be the [inaudible] of L, and then we want to find the value of theta for which the derivative of L is zero, and therefore must be a local optimum. Does this make sense? Any questions about this?
Student: [Inaudible]
Instructor (Andrew Ng) :The answer to that is fairly complicated. There are conditions on F that would guarantee that this will work. They are fairly complicated, and this is more complex than I want to go into now. In practice, this works very well for logistic regression, and for sort of generalizing any models I’ll talk about later.
Student: [Inaudible]
Instructor (Andrew Ng) :Yeah, it usually doesn’t matter. When I implement this, I usually just initialize theta zero to zero to just initialize the parameters to the – back to all zeros, and usually this works fine. It’s usually not a huge deal how you initialize theta.
Student: [Inaudible] or is it just different conversions?
Instructor (Andrew Ng) :Let me say some things about that that’ll sort of answer it. All of these algorithms tend not to – converges problems, and all of these algorithms will generally converge, unless you choose too large a linear rate for gradient ascent or something. But the speeds of conversions of these algorithms are very different.
So it turns out that Newton’s Method is an algorithm that enjoys extremely fast conversions. The technical term is that it enjoys a property called [inaudible] conversions. Don’t know [inaudible] what that means, but just stated informally, it means that [inaudible] every iteration of Newton’s Method will double the number of significant digits that your solution is accurate to. Just lots of constant factors.
Suppose that on a certain iteration your solution is within 0.01 at the optimum, so you have 0.01 error. Then after one iteration, your error will be on the order of 0.001, and after another iteration, your error will be on the order of 0.0001. So this is called [inaudible] conversions because you essentially get to square the error on every iteration of Newton’s Method.
[Inaudible] result that holds only when your [inaudible] cause the optimum anyway, so this is the theoretical result that says it’s true, but because of constant factors and so on, may paint a slightly rosier picture than might be accurate.
But the fact is, when you implement – when I implement Newton’s Method for logistic regression, usually converges like a dozen iterations or so for most reasonable size problems of tens of hundreds of features.
So one thing I should talk about, which is what I wrote down over there was actually Newton’s Method for the case of theta being a single-row number. The generalization to Newton’s Method for when theta is a vector rather than when theta is just a row number is the following, which is that theta T plus one is theta T plus – and then we have the second derivative divided by the first – the first derivative divided by the second derivative.
And the appropriate generalization is this, where this is the usual gradient of your objective, and each [inaudible] is a matrix called a Hessian, which is just a matrix of second derivative where HIJ equals – okay.
So just to sort of – the first derivative divided by the second derivative, now you have a vector of first derivatives times sort of the inverse of the matrix of second derivatives. So this is sort of just the same thing [inaudible] of multiple dimensions.
So for logistic regression, again, use the – for a reasonable number of features and training examples – when I run this algorithm, usually you see a conversion anywhere from sort of [inaudible] to like a dozen or so other [inaudible].
To compare to gradient ascent, it’s [inaudible] to gradient ascent, this usually means far fewer iterations to converge. Compared to gradient ascent, let’s say [inaudible] gradient ascent, the disadvantage of Newton’s Method is that on every iteration you need to invert the Hessian.
So the Hessian will be an N-by-N matrix, or an N plus one by N plus one-dimensional matrix if N is the number of features. And so if you have a large number of features in your learning problem, if you have tens of thousands of features, then inverting H could be a slightly computationally expensive step. But for smaller, more reasonable numbers of features, this is usually a very [inaudible]. Question?
Student: [Inaudible]
Instructor (Andrew Ng) :Let’s see. I think you’re right. That should probably be a minus. Do you have [inaudible]? Yeah, thanks. Yeah, X to a minus.
Thank you. [Inaudible] problem also. I wrote down this algorithm to find the maximum likely estimate of the parameters for logistic regression. I wrote this down for maximizing a function. So I’ll leave you to think about this yourself.
If I wanted to use Newton’s Method to minimize the function, how does the algorithm change? All right. So I’ll leave you to think about that. So in other words, it’s not the maximizations. How does the algorithm change if you want to use it for minimization? Actually, the answer is that it doesn’t change. I’ll leave you to work that out yourself why, okay.
And what I want to do now is show that both of these are special cases of the cause of distribution that’s called the exponential family distribution. And in particular, we’ll say that the cost of distributions, like the [inaudible] distributions that you get as you vary theta, we’ll say the cost of distributions is in the exponential family if it can be written in the following form. P of Y parameterized by theta is equal to B of Y [inaudible], okay.
Let me just get some of these terms, names, and then – let me – I’ll say a bit more about what this means. So [inaudible] is called the natural parameter of the distribution, and T of Y is called the sufficient statistic. Usually, for many of the examples we’ll see, including the [inaudible] and the Gaussian, T of Y is just equal to Y. So for most of this lecture you can mentally replace T of Y to be equal to Y, although this won’t be true for the very fine example we do today, but mentally, you think of T of Y as equal to Y.
And so for a given choice of these functions, A, B and T, all right – so we’re gonna sort of fix the forms of the functions A, B and T. Then this formula defines, again, a set of distributions. It defines the cause of distributions that is now parameterized by [inaudible].
So again, let’s write down specific formulas for A, B and T, true specific choices of A, B and T. Then as I vary [inaudible] I get different distributions. And I’m going to show that the [inaudible] – I’m going to show that the [inaudible] and the Gaussians are special cases of exponential family distributions. And by that I mean that I can choose specific functions, A, B and T, so that this becomes the formula of the distributions of either a [inaudible] or a Gaussian.
And then again, as I vary [inaudible], I’ll get [inaudible], distributions with different means, or as I vary [inaudible], I’ll get Gaussian distributions with different means for my fixed values of A, B and T.
And for those of you that know what a sufficient statistic and statistics is, T of Y actually is a sufficient statistic in the formal sense of sufficient statistic for a probability distribution. They may have seen it in a statistics class. If you don’t know what a sufficient statistic is, don’t worry about. We sort of don’t need that property today.
Okay. So – oh, one last comment. Often, T of Y is equal to Y, and in many of these cases, [inaudible] is also just a raw number. So in many cases, the parameter of this distribution is just a raw number, and [inaudible] transposed T of Y is just a product of raw numbers. So again, that would be true for our first two examples, but now for the last example I’ll do today.
So now we’ll show that the [inaudible] and the Gaussian are examples of exponential family distributions. We’ll start with the [inaudible]. So the [inaudible] distribution with [inaudible] – I guess I wrote this down already. PFY equals one [inaudible] by phi, [inaudible] equal to phi. So the parameter of phi specifies the probability that Y equals one.
And so my goal now is to choose T, A and B, or is to choose A, B and T so that my formula for the exponential family becomes identical to my formula for the distribution of a [inaudible].
So probability of Y parameterized by phi is equal to that, all right. And you already saw sort of a similar exponential notation where we talked about logistic regression. The probability of Y being one is phi, the probability of Y being zero is one minus phi, so we can write this compactly as phi to the Y times one minus phi to the one minus Y.
So I’m gonna take the exponent of the log of this, an exponentiation in taking log [inaudible] cancel each other out [inaudible]. And this is equal to E to the Y. And so [inaudible] is to be T of Y, and this will be minus A of [inaudible]. And then B of Y is just one, so B of Y doesn’t matter.
Just take a second to look through this and make sure it makes sense. I’ll clean another board while you do that.
So now let’s write down a few more things. Just copying from the previous board, we had that [inaudible] zero four equal to log phi over one minus phi.
[Inaudible] so if I want to do the [inaudible] take this formula, and if you invert it, if you solve for phi – excuse me, if you solve for theta as a function of phi, which is really [inaudible] is the function of phi. Just invert this formula. You find that phi is one over one plus [inaudible] minus [inaudible]. And so somehow the logistic function magically falls out of this. We’ll take this even this even further later.
Again, copying definitions from the board on – from the previous board, A of [inaudible] I said is minus log of one minus phi. So again, phi and [inaudible] are function of each other, all right. So [inaudible] depends on phi, and phi depends on [inaudible].
So if I plug in this definition for [inaudible] into this – excuse me, plug in this definition for phi into that, I’ll find that A of [inaudible] is therefore equal to log one plus [inaudible] to [inaudible]. And again, this is just algebra. This is not terribly interesting. And just to complete – excuse me. And just to complete the rest of this, T of Y is equal to Y, and B of Y is equal to one, okay.
So just to recap what we’ve done, we’ve come up with a certain choice of functions A, T and B, so then my formula for the exponential family distribution now becomes exactly the formula for the distributions, or for the probability mass function of the [inaudible] distribution. And the natural parameter [inaudible] has a certain relationship of the original parameter of the [inaudible]. Question?
Student: [Inaudible]
Instructor (Andrew Ng) :Let’s see. [Inaudible].
oh, no, just the previous lecture when we were dividing the maximum likelihood estimate for the parameters of ordinary [inaudible] squares. We showed that the parameter for [inaudible] squared didn’t matter.
When we divide the [inaudible] model for [inaudible] square [inaudible], we said that no matter what [inaudible] square was, we end up with the same value of the parameters.
So for the purposes of just writing lesson, today’s lecture, and not taking account [inaudible] squared, I’m just going to set [inaudible] squared to be for the one, okay, so as to not worry about it.
Lecture [inaudible] talks a little bit more about this, but I’m just gonna – just to make [inaudible] in class a bit easier and simpler today, let’s just say that [inaudible] square equals one. [Inaudible] square is essentially just a scaling factor on the variable Y.
So in that case, the Gaussian density is given by this, [inaudible] squared. And – well, by a couple of steps of algebra, which I’m not going to do, but is written out in [inaudible] in the lecture now so you can download. This is one root two pie, E to the minus one-half Y squared times E to E. New Y minus one-half [inaudible] squared, okay. So I’m just not doing the algebra.
And so that’s B of Y, we have [inaudible] that’s equal to [inaudible]. P of Y equals Y, and – well, A of [inaudible] is equal to minus one-half – actually, I think that should be plus one-half. Have I got that right? Yeah, sorry. Let’s see – excuse me. Plus sign there, okay. If you minus one-half [inaudible] squared, and because [inaudible] is equal to [inaudible], this is just minus one-half [inaudible] squared, okay.
And so this would be a specific choice again of A, B and T that expresses the Gaussian density in the form of an exponential family distribution. And in this case, the relationship between [inaudible] and [inaudible] is that [inaudible] is just equal to [inaudible], so the [inaudible] of the Gaussian is just equal to the natural parameter of the exponential family distribution.
Student: Minus half.
Instructor (Andrew Ng) :Oh, this is minus half?
Student: [Inaudible]
Instructor (Andrew Ng) :Oh, okay, thanks. And so – guessing that should be plus then. Is that right? Okay. Oh, yes, you’re right. Thank you. All right.
And so [inaudible] result that if you’ve taken a look in undergrad statistics class, turns out that most of the “textbook distributions,” not all, but most of them, can be written in the form of an exponential family distribution.
So you saw the Gaussian, the normal distribution. It turns out the [inaudible] in normal distribution, which is a generalization of Gaussian random variables, so it’s a high dimension to vectors. The [inaudible] normal distribution is also in the exponential family.
You saw the [inaudible] as an exponential family. It turns out the [inaudible] distribution is too, all right. So the [inaudible] models outcomes over zero and one. They’ll be coin tosses with two outcomes. The [inaudible] models outcomes over K possible values. That’s also an exponential families distribution.
You may have heard of the Parson distribution. And so the Parson distribution is often used for modeling counts. Things like the number of radioactive decays in a sample, or the number of customers to your website, the numbers of visitors arriving in a store. The Parson distribution is also in the exponential family.
So are the gamma and the exponential distributions, if you’ve heard of them. So the gamma and the exponential distributions are distributions of the positive numbers. So they’re often used in model intervals, like if you’re standing at the bus stop and you want to ask, “When is the next bus likely to arrive? How long do I have to wait for my bus to arrive?” Often you model that with sort of gamma distribution or exponential families, or the exponential distribution. Those are also in the exponential family.
Even more [inaudible] distributions, like the [inaudible] and the [inaudible] distributions, these are probably distributions over fractions, are already probability distributions over probability distributions. And also things like the Wisha distribution, which is the distribution over covariance matrices. So all of these, it turns out, can be written in the form of exponential family distributions.
Well, and in the problem set where he asks you to take one of these distributions and write it in the form of the exponential family distribution, and derive a generalized linear model for it, okay.
Which brings me to the next topic of having chosen and exponential family distribution, how do you use it to derive a generalized linear model? So generalized linear models are often abbreviated GLM’s. And I’m going to write down the three assumptions. You can think of them as assumptions, or you can think of them as design choices, that will then allow me to sort of turn a crank and come up with a generalized linear model.
So the first one is – I’m going to assume that given my input X and my parameters theta, I’m going to assume that the variable Y, the output Y, or the response variable Y I’m trying to predict is distributed exponential family with some natural parameter [inaudible].
And so this means that there is some specific choice of those functions, A, B and T so that the conditional distribution of Y given X and parameterized by theta, those
So let’s work through an example. [Inaudible] equals theta transpose X works for the case where [inaudible] is a real number. For the more general case, you would have [inaudible] I equals theta I, transpose X if [inaudible] is a vector rather than a real number. But again, most of the examples [inaudible] will just be a real number.
All right. So let’s work through the [inaudible] example. You’ll see where Y given X parameterized by theta – this is a distributed exponential family with natural parameter [inaudible]. And for the [inaudible] distribution, I’m going to choose A, B and T to be the specific forms that cause those exponential families to become the [inaudible] distribution. This is the example we worked through just now, the first example we worked through just now.
So – oh, and we also have – so for any fixed value of X and theta, my hypothesis, my learning algorithm will make a prediction, or will make – will sort of output [inaudible] of X, which is by my, I guess, assumption [inaudible].
Watch our learning algorithm to output the expected value of Y given X and parameterized by theta, where Y can take on only the value zero and one, then the expected value of Y is just equal to the probability that Y is equal to one. So the expected value of a [inaudible] variable is just equal to the probability that it’s equal to one.
And so the probability that Y equals one is just equal to phi because that’s the parameter of my [inaudible] distribution. Phi is, by definition, I guess, is the probability of my [inaudible] distribution [inaudible] value of one.
Which we worked out previously, phi was one over one plus E to the negative [inaudible]. So we worked this out on our previous board. This is the relationship – so when we wrote down the [inaudible] distribution in the form of an exponential family, we worked out what the relationship was between phi and [inaudible], and it was this. So we worked out the relationship between the expected value of Y and [inaudible] was this relationship.
And lastly, because we made the design choice, or the assumption that [inaudible] and theta are linearly related. This is therefore equal to one over one plus E to the minus theta, transpose X.
And so that’s how I come up with the logistic regression algorithm when you have a variable Y – when you have a [inaudible] variable Y, or also response variable Y that takes on two values, and then you choose to model variable [inaudible] distribution. Are you sure this does make sense? Raise your hand if this makes sense. Yeah, okay, cool.
So I hope you get the ease of use of this, or sort of the power of this. The only decision I made was really, I said Y – let’s say I have a new machine-learning problem and I’m trying to predict the value of a variable Y that happens to take on two values. Then the only decision I need to make is I chose [inaudible] distribution.
I say I want to model – I want to assume that given X and theta, I’m going to assume Y is distributed [inaudible]. That’s the only decision I made. And then everything else follows automatically having made the decision to model Y given X and parameterized by theta as being [inaudible].
In the same way you can choose a different distribution, you can choose Y as Parson or Y as gamma or Y as whatever, and follow a similar process and come up with a different model and different learning algorithm. Come up with a different generalized linear model for whatever learning algorithm you’re faced with.
This tiny little notation, the function G that relates G of [inaudible] that relates the natural parameter to the expected value of Y, which in this case, one over one plus [inaudible] minus [inaudible], this is called the canonical response function. And G inverse is called the canonical link function.
These aren’t a huge deal. I won’t use this terminology a lot. I’m just mentioning those in case you hear about – people talk about generalized linear models, and if they talk about canonical response functions or canonical link functions, just so you know there’s all of this.
Actually, many techs actually use the reverse way. This is G inverse and this is G, but this notation turns out to be more consistent with other algorithms in machine learning. So I’m going to use this notation. But I probably won’t use the terms canonical response functions and canonical link functions in lecture a lot, so just – I don’t know. I’m not big on memorizing lots of names of things. I’m just tossing those out there in case you see it elsewhere.
Okay. You know what, I think in the interest of time, I’m going to skip over the Gaussian example. But again, just like I said, [inaudible], Y is [inaudible], different variation I get of logistic regression. You can do the same thing with the Gaussian distribution and end up with ordinary [inaudible] squares model.
The problem with Gaussian is that it’s almost so simple that when you see it for the first time that it’s sometimes more confusing than the [inaudible] model because it looks so simple, it looks like it has to be more complicated. So let me just skip that and leave you to read about the Gaussian example in the lecture notes.
And what I want to do is actually go through a more complex example. Question?
Student: [Inaudible]
Instructor (Andrew Ng) :Okay, right. So how do choose what theory will be? We’ll get to that in the end. What you have there is the logistic regression model, which is a [inaudible] model that assumes the probability of Y given X is given by a certain form.
But if I choose this as my parameterization of the [inaudible], then my parameter’s actually redundant because if these are probabilities, then you have to sum up the one. And therefore for example, I can derive the last parameter, phi K, as one minus phi one, up to phi K minus one. So this would be a redundant parameterization from [inaudible]. The result is over-parameterized.
And so for purposes of this [inaudible], I’m going to treat my parameters of my [inaudible] as phi one, phi two, up to phi K minus one. And I won’t think of phi K as a parameter. I’ll just – so my parameters are just – I just have K minus one parameters, parameterizing my [inaudible].
And sometimes I write phi K in my derivations as well, and you should think of phi K as just a shorthand for this, for one minus the rest of the parameters, okay.
So it turns out the [inaudible] is one of the few examples where T of Y – it’s one of the examples where T of Y is not equal to Y. So in this case, Y is on of K possible values.
And so T of Y would be defined as follows; T of one is going to be a vector with a one and zeros everywhere else. T of two is going to be a zero, one, zero and so on. Except that these are going to be K minus one-dimensional vectors.
And so T of K minus one is going to be zero, zero, zero, one. And T of K is going to be the vector of all zeros. So this is just how I’m choosing to define T of Y to write down the [inaudible] in the form of an exponential family distribution. Again, these are K minus one-dimensional vectors.
So this is a good point to introduce one more useful piece of notation, which is called indicator function notation. So I’m going to write one, and then curly braces. And if I write a true statement inside, then the indicator of that statement is going to be one. Then I write one, and then I write a false statement inside, then the value of this indicator function is going to be a zero.
For example, if I write indicator two equals three [inaudible] that’s false, and so this is equal to zero. Whereas indicator [inaudible] plus one equals two, I wrote down a true statement inside. And so the indicator of the statement was equal to one. So the indicator function is just a very useful notation for indicating sort of truth or falsehood of the statement inside.
And so – actually, let’s do this here. To combine both of these, right, if I carve out a bit of space here – so if I use – so TY is a vector. Y is one of K values, and so TY is one of these K vectors. If I use TY as [inaudible] to denote the [inaudible] element of the vector TY, then TY – the [inaudible] element of the vector TY is just equal to indicator for whether Y is equal to I.
Just take a – let me clean a couple more boards. Take a look at this for a second and make sure you understand why that – make sure you understand all that notation and why this is true.
All right. Actually, raise your hand if this equation makes sense to you. Most of you, not all, okay. [Inaudible].
Just as one kind of [inaudible], suppose Y is equal to one – let’s say – let me see. Suppose Y is equal to one, right, so TY is equal to this vector, and therefore the first element of this vector will be one, and the rest of the elements will be equal to zero.
And so – let me try that again, I’m sorry. Let’s say I want to ask – I want to look at the [inaudible] element of the vector TY, and I want to know is this one or zero. All right. Well, this will be one. The [inaudible] element of the vector TY will be equal to one if, and only if Y is equal to I.
Because for example, if Y is equal to one, then only the first element of this vector will be zero. If Y is equal to two, then only the second element of the vector will be zero and so on. So the question of whether or not – whether the [inaudible] element of this vector, TY, is equal to one is answered by just asking is Y equal to I.
Okay. If you’re still not quite sure why that’s true, go home and think about it a bit more. And I think I – and take a look at the lecture notes as well, maybe that’ll help. At least for now, only just take my word for it.
So let’s go ahead and write out the distribution for the [inaudible] in an exponential family form. So PFY is equal to phi one. Indicator Y equals one times phi two. Indicator Y equals to up to phi K times indicator Y equals K. And again, phi K is not a parameter of the distribution. Phi K is a shorthand for one minus phi one minus phi two minus the rest.
And so using this equation on the left as well, I can also write this as phi one times TY one, phi two, TY two, dot, dot, dot. Phi K minus one, TY, K minus one times phi K. And then one minus [inaudible]. That should be K.
And it turns out – it takes some of the steps of algebra that I don't have time to show. It turns out, you can simplify this into – well, the exponential family form where [inaudible] is a vector, this is a K minus one-dimensional vector, and – well, okay.
So deriving this is a few steps of algebra that you can work out yourself, but I won’t do here. And so using my definition for TY, and by choosing [inaudible] A and B this way, I can take my distribution from [inaudible] and write it out in a form of an exponential family distribution.
X and then theta.” And so you chose [inaudible] as the exponential family. Then you sort of turn the crank. And everything else I wrote down follows automatically from you have made the choice of using [inaudible] distribution as your choice of exponential family.
And then what you do is you then have this training set, X, I, Y, I up to X, M, Y, M. So you’re doing the training set. We’re now [inaudible] the value of Y takes on one of K possible values.
And what you do is you then find the parameters of the model by maximum likelihood. So you write down the likelihood of the parameters, and you maximize the likelihood.
So what’s the likelihood? Well, the likelihood, as usual, is the product of your training set of P of YI given XI parameterized by theta. That’s the likelihood, same as we had before. And that’s product of your training set of – let me write these down now. YI equals one times phi two of indicator YI equals two, dot, dot, dot, to phi K of indicator YI equals K.
Where, for example, phi one depends on theta through this formula. It is E to the theta one, transpose X over one plus sum over J – well, that formula I had just now. And so phi one here is really a shorthand for this formula, and similarly for phi two and so on, up to phi K, where phi K is one minus all of these things. All right.
So this is a –this formula looks more complicated than it really is. What you really do is you write this down, then you take logs, compute a derivative of this formula [inaudible] theta, and apply say gradient ascent to maximize the likelihood.
Student: What are the rows of theta? [Inaudible] it’s just been a vector, right? And now it looks like it’s two-dimensional.
Instructor (Andrew Ng) :Yeah. In the notation of the [inaudible] I think have theta one through theta K minus one. I’ve been thinking of each of these as – and N plus one- dimensional vector. If X is N plus one-dimensional, then I’ve been – see, I think if you have a set of parameters comprising K minus one vectors, and each of these is a – you could group all of these together and make these, but I just haven’t been doing that. [Inaudible] the derivative of K minus one parameter vectors.
Student: [Inaudible], what do they correspond to?
Instructor (Andrew Ng) :[Inaudible]. We’re sort of out of time. Let me take that offline. It’s hard to answer in the same way that the logistic regression – what does theta correspond to in logistic regression? You can sort of answer that as sort of –
Student: Yeah. It’s kind of like the [inaudible] feature –
Instructor (Andrew Ng) :Yeah. Sort of similar interpretation, yeah. That’s good. I think I’m running a little bit late. Why don’t I – why don’t we officially close for the day, but you can come up if you more questions and take them offline. Thanks.
[End of Audio]
Duration: 76 minutes