Machine learning is the science of getting computers to act without being explicitly programmed. In the past decade, machine learning has given us self-driving cars, practical speech recognition, effective web search, and a vastly improved understanding of the human genome. Machine learning is so pervasive today that you probably use it dozens of times a day without knowing it. Many researchers also think it is the best way to make progress towards human-level AI. In this class, you will learn about the most effective machine learning techniques, and gain practice implementing them and getting them to work for yourself. More importantly, you'll learn about not only the theoretical underpinnings of learning, but also gain the practical know-how needed to quickly and powerfully apply these techniques to new problems. Finally, you'll learn about some of Silicon Valley's best practices in innovation as it pertains to machine learning and AI.
This course provides a broad introduction to machine learning, datamining, and statistical pattern recognition. Topics include: (i) Supervised learning (parametric/non-parametric algorithms, support vector machines, kernels, neural networks). (ii) Unsupervised learning (clustering, dimensionality reduction, recommender systems, deep learning). (iii) Best practices in machine learning (bias/variance theory; innovation process in machine learning and AI). The course will also draw from numerous case studies and applications, so that you'll also learn how to apply learning algorithms to building smart robots (perception, control), text understanding (web search, anti-spam), computer vision, medical informatics, audio, database mining, and other areas.

From the lesson

Large Scale Machine Learning

Machine learning works best when there is an abundance of data to leverage for training. In this module, we discuss how to apply the machine learning algorithms with large datasets.

Co-founder, Coursera; Adjunct Professor, Stanford University; formerly head of Baidu AI Group/Google Brain

You now know about the stochastic gradient descent algorithm.

Â

But when you're running the algorithm, how do you make sure that it's completely debugged and is converging okay?

Â

Equally important, how do you tune the learning rate alpha with Stochastic Gradient Descent.

Â

In this video we'll talk about some techniques for doing these things, for making sure it's converging and for picking the learning rate alpha.

Â

Back when we were using batch gradient descent, our standard way for making sure that

Â

gradient descent was converging was we would plot the optimization cost function as a function of the number of iterations.

Â

So that was the cost function and we would make sure that this cost function is decreasing on every iteration.

Â

When the training set sizes were small, we could do that because we could compute the sum pretty efficiently.

Â

But when you have a massive training set size then you don't want to have to pause your algorithm periodically.

Â

You don't want to have to pause stochastic gradient descent periodically in order to compute this cost function

Â

since it requires a sum of your entire training set size.

Â

And the whole point of stochastic gradient was that you wanted to start to make progress

Â

after looking at just a single example without needing to occasionally scan through your entire training set

Â

right in the middle of the algorithm, just to compute things like the cost function of the entire training set.

Â

So for stochastic gradient descent, in order to check the algorithm is converging, here's what we can do instead.

Â

Let's take the definition of the cost that we had previously.

Â

So the cost of the parameters theta with respect to a single training example is just one half of the square error on that training example.

Â

Then, while stochastic gradient descent is learning, right before we train on a specific example.

Â

So, in stochastic gradient descent we're going to look at the examples xi, yi, in order, and

Â

then sort of take a little update with respect to this example.

Â

And we go on to the next example, xi plus 1, yi plus 1, and so on, right?

Â

That's what stochastic gradient descent does.

Â

So, while the algorithm is looking at the example xi, yi, but before it has updated the parameters theta

Â

using that an example, let's compute the cost of that example.

Â

Just to say the same thing again, but using slightly different words.

Â

A stochastic gradient descent is scanning through our training set right before we have updated theta using a specific training example x(i) comma y(i)

Â

let's compute how well our hypothesis is doing on that training example.

Â

And we want to do this before updating theta because if we've just updated theta using example,

Â

you know, that it might be doing better on that example than what would be representative.

Â

Finally, in order to check for the convergence of stochastic gradient descent, what we can do is every, say, every thousand iterations,

Â

we can plot these costs that we've been computing in the previous step.

Â

We can plot those costs average over, say, the last thousand examples processed by the algorithm.

Â

And if you do this, it kind of gives you a running estimate of how well the algorithm is doing.

Â

on, you know, the last 1000 training examples that your algorithm has seen.

Â

So, in contrast to computing J<u>train periodically which needed to scan through the entire training set.</u>

Â

With this other procedure, well, as part of stochastic gradient descent,

Â

it doesn't cost much to compute these costs as well right before updating to parameter theta.

Â

And all we're doing is every thousand integrations or so, we just average the last 1,000 costs that we computed and plot that.

Â

And by looking at those plots, this will allow us to check if stochastic gradient descent is converging.

Â

So here are a few examples of what these plots might look like.

Â

Suppose you have plotted the cost average over the last thousand examples,

Â

because these are averaged over just a thousand examples, they are going to be a little bit noisy and so,

Â

it may not decrease on every single iteration.

Â

Then if you get a figure that looks like this, So the plot is noisy

Â

because it's average over, you know, just a small subset, say a thousand training examples.

Â

If you get a figure that looks like this, you know that would be a pretty decent run with the algorithm,

Â

maybe, where it looks like the cost has gone down and then this plateau that looks kind of flattened out, you know, starting from around that point.

Â

look like, this is what your cost looks like then maybe your learning algorithm has converged.

Â

If you want to try using a smaller learning rate, something you might see is that

Â

the algorithm may initially learn more slowly so the cost goes down more slowly.

Â

But then eventually you have a smaller learning rate is actually possible for the algorithm to end up at a, maybe very slightly better solution.

Â

So the red line may represent the behavior of stochastic gradient descent using a slower, using a smaller leaning rate.

Â

And the reason this is the case is because, you remember, stochastic gradient descent doesn't just converge to the global minimum,

Â

is that what it does is the parameters will oscillate a bit around the global minimum.

Â

And so by using a smaller learning rate, you'll end up with smaller oscillations.

Â

And sometimes this little difference will be negligible

Â

and sometimes with a smaller than you can get a slightly better value for the parameters.

Â

Here are some other things that might happen.

Â

Let's say you run stochastic gradient descent and you average over a thousand examples when plotting these costs.

Â

So, you know, here might be the result of another one of these plots.

Â

Then again, it kind of looks like it's converged.

Â

If you were to take this number, a thousand, and increase to averaging over 5 thousand examples.

Â

Then it's possible that you might get a smoother curve that looks more like this.

Â

And by averaging over, say 5,000 examples instead of 1,000, you might be able to get a smoother curve like this.

Â

And so that's the effect of increasing the number of examples you average over.

Â

The disadvantage of making this too big of course is that now you get one date point only every 5,000 examples.

Â

And so the feedback you get on how well your learning learning algorithm is doing is, sort of, maybe it's more delayed

Â

because you get one data point on your plot only every 5,000 examples rather than every 1,000 examples.

Â

Along a similar vein some times you may run a gradient descent and end up with a plot that looks like this.

Â

And with a plot that looks like this, you know, it looks like the cost just is not decreasing at all.

Â

It looks like the algorithm is just not learning.

Â

It's just, looks like this here a flat curve and the cost is just not decreasing.

Â

But again if you were to increase this to averaging over a larger number of examples

Â

it is possible that you see something like this red line

Â

it looks like the cost actually is decreasing, it's just that the blue line averaging over 2, 3 examples,

Â

the blue line was too noisy so you couldn't see the actual trend in the cost actually decreasing

Â

and possibly averaging over 5,000 examples instead of 1,000 may help.

Â

Of course we averaged over a larger number examples that we've averaged here over 5,000 examples,

Â

I'm just using a different color, it is also possible that you that see a learning curve ends up looking like this.

Â

That it's still flat even when you average over a larger number of examples.

Â

And as you get that, then that's maybe just a more firm verification that

Â

unfortunately the algorithm just isn't learning much for whatever reason.

Â

And you need to either change the learning rate or change the features or change something else about the algorithm.

Â

Finally, one last thing that you might see would be if you were to plot these curves

Â

and you see a curve that looks like this, where it actually looks like it's increasing.

Â

And if that's the case then this is a sign that the algorithm is diverging.

Â

And what you really should do is use a smaller value of the learning rate alpha.

Â

So hopefully this gives you a sense of the range of phenomena you might see

Â

when you plot these cost average over some range of examples as well as

Â

suggests the sorts of things you might try to do in response to seeing different plots.

Â

So if the plots looks too noisy, or if it wiggles up and down too much, then try increasing the number of examples

Â

you're averaging over so you can see the overall trend in the plot better.

Â

And if you see that the errors are actually increasing, the costs are actually increasing, try using a smaller value of alpha.

Â

Finally, it's worth examining the issue of the learning rate just a little bit more.

Â

We saw that when we run stochastic gradient descent, the algorithm will start here and sort of meander towards the minimum

Â

And then it won't really converge, and instead it'll wander around the minimum forever.

Â

And so you end up with a parameter value that is hopefully close to the global minimum that won't be exact at the global minimum.

Â

In most typical implementations of stochastic gradient descent, the learning rate alpha is typically held constant.

Â

And so what you we end up is exactly a picture like this.

Â

If you want stochastic gradient descent to actually converge to the global minimum,

Â

there's one thing which you can do which is you can slowly decrease the learning rate alpha over time.

Â

So, a pretty typical way of doing that would be to set alpha equals some constant 1 divided by iteration number plus constant 2.

Â

So, iteration number is the number of iterations you've run of stochastic gradient descent,

Â

so it's really the number of training examples you've seen

Â

And const 1 and const 2 are additional parameters of the algorithm

Â

that you might have to play with a bit in order to get good performance.

Â

One of the reasons people tend not to do this is because you end up needing to spend time

Â

playing with these 2 extra parameters, constant 1 and constant 2, and so this makes the algorithm more finicky.

Â

You know, it's just more parameters able to fiddle with in order to make the algorithm work well.

Â

But if you manage to tune the parameters well, then the picture you can get is that

Â

the algorithm will actually around towards the minimum, but as it gets closer

Â

because you're decreasing the learning rate the meanderings will get smaller and smaller

Â

until it pretty much just to the global minimum. I hope this makes sense, right?

Â

And the reason this formula makes sense is because as the algorithm runs, the iteration number becomes large So alpha will slowly become small,

Â

and so you take smaller and smaller steps until it hopefully converges to the global minimum.

Â

So If you do slowly decrease alpha to zero you can end up with a slightly better hypothesis.

Â

But because of the extra work needed to fiddle with the constants and because frankly usually we're pretty happy

Â

with any parameter value that is, you know, pretty close to the global minimum.

Â

Typically this process of decreasing alpha slowly is usually not done and keeping the learning rate alpha constant

Â

is the more common application of stochastic gradient descent although you will see people use either version.

Â

To summarize in this video we talk about a way for approximately monitoring

Â

how the stochastic gradient descent is doing in terms for optimizing the cost function.

Â

And this is a method that does not require scanning over the entire training set periodically to compute the cost function on the entire training set.

Â

But instead it looks at say only the last thousand examples or so.

Â

And you can use this method both to make sure the stochastic gradient descent is okay and is converging

Â

or to use it to tune the learning rate alpha.

Â

Explore our Catalog

Join for free and get personalized recommendations, updates and offers.