So that's a demonstration of what this cost function is.

And this is very important because this whole idea of finding that minimum is

the key aspect in all of machine learning.

You want to find the best model,

to do that you have to minimize the cost function or the lost function.

And typically, we'll do this with gradient descent, but

there's a lot of other algorithms that come along to try to improve upon this.

And we will see more with gradient descent in future notebooks.

Now, let's get into doing linear regression with scikit-learn.

Again, as I showed you in the introduction of machine learning lesson,

using scikit-learn to perform machine learning is very simple.

We import our estimator, in this case, it's the linear regression estimator.

We create it and we may have to pass in some hyper parameters when we do it.

In this case, we are showing none but

we can specify some like the fit_intercept or normalize.

And then we fit the model and then we can predict the model.

So let's go back to the tips dataset, we're going to use that.

So first, we're going to split our data into training and testing.

We then apply this scikit-learn library and then this case we are going to make

a nice little plot first and then show the linear regression.

So here is our model, tip = 0.14 times total_bill.

And our model score is 39.9, that's not very good, right?

Ideally, you would have 100% accuracy.

But this is our first time, so we are just going to look at this.

We've color coded training and

testing data little bit differently and the model look somewhat reasonably.

It performs worst out here as the total_bill gets bigger.

There's some errors out here as well, but not too bad.

We can also look at the model residuals,

this is the differences between the model and the predicted value.

And so you can see that here and now I see why this value was so high,

that 39.9% wasn't 100% and that's because there is some serious scatter about this.

There's nothing that's too bad,

we don't see any indication of some systematic trend, so, for instance,

it's not like all the values out here at total_bill are well above the zero line.

That would indicate that our model might be under fitting the data.

That's something we always want to worry about.

So that's a reasonable first guess, and we can try other things as well, so

we can say this time let's fit an intercept.

So now you notice our model changes slightly and

our accuracy goes up, that's good.

And you can see the rest.

So this notebook walks you through these different steps.

The next thing is multivariate, can we use more than one independent feature?

And so here we are taking total_bill and size and extracting them out.

And the model just walks through making these, again, showing the same things.

The next step, though, is categorical features.