OK.
Welcome back.
Let's revisit our little list here of what we're covering to see where we're up to.
OK so we've done zero and end to end psychic learn workflow and we've done one.
Getting your data ready.
So now we're going to do.
Number two.
Choose the right estimate at slash algorithm for our problems.
Let's make a little heading for that too.
Choosing the right estimate a slash algorithm for our problem.
Now a little thing to note here is that psychic learn let's just put it here.
Psychic loan users estimate as another term for machine learning model or algorithm.
So that's an important thing to note.
Like you come across if you're using the psychic loan documentation or if you're just browsing general
machine learning stuff online you'll hear a few different names for it.
So machine learning model machine learning algorithm or estimate.
In the case of psychic line they kind of had their own nomenclature to just make things a bit more easier
across the library.
But if you hear those kind of times just remember it's talking about using a machine learning model.
OK.
How do we go about this.
Well some other things to note is that first of all before you choose an estimate slash algorithm for
your problem is you have to figure out what kind of problem are you working with.
And up here we've seen a few different types of problems but the main ones we're going to be looking
at are classification a.k.a. predicting whether a sample is one thing or another.
And regression predicting a number so classification is like our heart disease problem.
We're trying to predict whether someone has heart disease or not.
And regression is we're trying to predict a number like with the Boston Housing dataset or with our
car sales data set.
We're trying to predict a house price or a car price that doesn't look very good.
Let's go dot point.
This thing's got to look good right.
So in the previous examples I've kind of just randomly imported this random forest regress.
But where did I get that from.
And I'll let you in on a little secret.
It's not that trivial.
There are a lot of different machine learning models but psychic line has made something very helpful
and I'm very excited to show it to you.
Let's have a look.
So let's go google S.K. loan email map choosing the right estimate.
This is what we want this when you first see this.
It's gonna look like a whole bunch of just different jargon going through but as we start to dive into
it we'll start to realize oh wow this has some really useful things that we can use in our problems
our machine learning problems and what is this.
Well at this Web site here you just go SDK line or socket line machine learning map and Google.
And this is choosing the right estimate.
Remember estimating so I line is the same as machine learning model or machine learning algorithm.
And the documentation here says often the hardest part of solving machine learning problem can be finding
the right estimate for the job.
Yes.
Different estimates are better suited for different types of data and different problems.
That makes sense if we have a classification problem we might want to use one of these estimates.
And if we have a regression problem we won't want to use one of these estimates and then for something
like a clustering problem we have these estimates.
And there was something like a dimensionality reduction problem.
You I want to use one of these.
But let's get hands on right because at the moment this this graph or this flow chart this map whatever
you want to call it it can seem a bit confusing to begin with.
So what we're going to do is get hands on with a problem.
So if we start here first we need some data.
So this is what these little blue steps are you do you have above 50 samples.
No.
Get more data.
Simple.
Do we have above 50 samples.
Yes.
Predicting a category.
Yes.
Do we have labeled data.
Yes.
Do we have under 100 k samples.
Yes.
Use linear SPC.
Okay.
All right.
Enough talk.
Let's get back to our notebook and start writing some code.
What we're going to do is to begin with two point one we'll see how we did regression just recently
so we'll see how we would pick an estimate slash algorithm for a regression problem.
So let's do this.
I'll make two point one.
Picking a machine learning model for our regression problem beautiful.
And so what we're going to do is we're going to use one of socket loans built in datasets and that's
the Boston Housing data set.
So let's go import Boston housing data set and we can do that from S.K. learned on data sets.
Import load Boston and then we want to go.
Boston just to settle up Eagles load Boston and then we want to see what it looks like.
Boston OK.
So it imports as a dictionary we've got data as one of the keys.
Target is one of the keys.
And then I think we have a feature names.
What can we do with this.
Well let's first turn it into a panda's data frame so that we can see it a little bit better than being
a dictionary.
So we'll go to Boston DNF.
This is one of the first steps you'll you usually do with any kind of problem with any kind of data
set is try to get it into a panda's data frame.
Right.
Because we've seen what pandas is capable of and we know it looks good and we know it's pretty malleable
and we can just do a whole bunch of different things one is in Japan this data frame.
So rather than having an a dictionary we'll get it into a data frame and then we want to set up Boston
DCF.
And I'm kind of typing here without talking but essentially what I'm doing is I'm taking the data key
from the Boston dictionary and setting the columns to be the featured names from the dictionary and
then creating a target column here.
This is what we're trying to predict by setting it to PD series and then taking the target key from
the Boston dictionary.
So right now Boston is a dictionary and we're going to turn it into Boston DNF which is a data frame.
So let's see what this bad boy looks like key era features names it might just be feature names columns
lots of typos.
This is what happens when you type and talk.
Okay.
Excellent.
So what can we see here.
Well we've got cram Xian index charts.
Not sure what all of these are.
But it's got a target column.
So I'm assuming that's what we're trying to predict and we can figure out what this actually is by just
going as K line Boston housing dataset we're looking at data sets.
Lloyd Boston so this is what we've just done we've called this function from the S.K. lined up data
sets module.
We can read more on the user guide.
I've seen this before and it's one kind of familiar with it.
But if you're first looking at it you might have to dive in.
So this is just going to give us a data dictionary of what the columns that we're dealing with.
So if we see Crim is per capita crime rate per town Yep.
OK.
And then zone proportion of residential land zoned for lots over 25000 square feet.
Yep.
OK.
So long story short what this dataset is is a whole bunch of different parameters about different towns
in Boston.
So each row of these Boston is a city in America by the way.
So each row is a different town in Boston and there's different features about this town.
You can read all of these here and what we're trying to do is use these features about the town to predict
the median house price.
And I believe this house price is in thousands and this data says a little bit all too that's why everything
is so cheap.
But the premise is here.
This is a regression problem.
So now we can figure out a few things about our data frame so we want how many samples we're going to
get.
Len Boston DNF five hundred and six.
Wonderful.
So now that we know we have five hundred and six samples and we have a regression problem and we have
labels what can we do we'll go back to our machine learning map we come right to the start and we go
okay we go follow this little little golden arrow.
Beautiful.
Do we have above 50 samples.
Yes.
See if we didn't have above 50 samples SBA loan will be telling us get more data which makes sense.
Are we predicting category.
No.
Are we predicting a quantity.
Yes because we are working on a regression problem.
Do we have over 100 k samples under 100 samples.
Yes.
Few features should be important.
We're actually not sure what this is.
So few features should be important.
What can we.
We've got 1 2 3 4 5 6 7 8 9 10 11 12 13.
We've got 13 features but we don't actually know whether a few of them will be important or not.
So let's just pretend no for the time being.
And so this is going to point us now to one of these green squares and within each of these green squares
is an estimate or a machine learning model.
So if we click on this one ridge regression this is gonna take us to the ridge regression and classification
documentation.
So it tells us red regression rage regression addresses some of the problems of ordinary least squares
and we got a whole bunch of math symbols but really we would just want to work out how we can use this
machine learning model.
Okay so from Mesquite loan import linear model Reg okay.
So we can just important like that.
Well let's see.
Let's go back let's get some code working.
Let's try the ridge progression model.
So if we go back up here we go from S K line input linear model and its linear model dot reach to use
the ridge progression but actually we don't want I just do it like that.
Let's skip a line of code and we can do it by going from S.K. line Don linear model import ridge and
then we're going to set up a random seed
MP don't random so we can make sure our results are reproducible and then we want to create the data.
So we're going to go X equals we've seen this before.
Boston D F don't drop.
We want to drop the target column for X because then it'll just be the features matrix.
Access equals one.
I'm going to put a few rows down here so we've got some space to see why it goes.
BOSTON THE F and this is going to be the target column because we want to use x to predict y right.
And then we want to go split into train and test sets.
We're going to go X train x test y train y test equals train test split x y test size we use 20 percent
again because that's a good general number you'll see that come up over and over again in machine learning
projects and then the next thing to do is because we've imported Ridge much like up here we've instantiated
the model with random forest.
So model equals random forest regress so we can do the same thing with Ridge.
So we go instantiate Ridge model and we'll call it the generic model again bridge and then we're going
to go modeled off it X train y train and then you want to go check the score of the ridge Ridge model
on test data model dot school X test y test beautiful look at that how quick was that.
So what did we do here.
Where did this come from.
Remember we went back to our machine learning map.
We started here.
We answered a few questions and follow the flow chart along here.
And we clicked on ridge regression.
And that took us to the documentation and we went here.
Okay.
There's some example code but we prefer to just start typing it out ourselves which is what we did.
He kind of skipped over looking at this because I wanted to just get it in here so you can get an example.
And so now what we've done is we've split our data into x and y we've got our Boston data frame here.
We've taken these columns because we want to use these columns to predict the target.
And so that's what we've done X and Y.
Now we split into train and tests and we've instantiated a bridge model because that's the model that
the map suggested we should use.
This bad boy here and then we fitted it to the data a.k.a. asked our model to find the patterns between
X train and Y train and then we evaluated our model on the test data set Wow that was actually surprisingly
easy.
Now this score What is this.
So this is if we press shift hab returns the coefficient of determination r squared of the prediction.
Now we'll look into more evaluation metrics as we go on.
But just remember the highest possible score you can get here is one point zero.
So if our model was to predict each of these columns exactly then it would get a score of one point
zero.
So zero point six x is not too bad right.
The closer to 1 the better what you might be asking is how do we.
How do we improve this score
Brian.
What if Ridge wasn't working.
And luckily if we go back to the machine learning map we've got a little error here that says not working
right.
So if our ridge regression wasn't performing as well as we wanted or wasn't working at all well this
arrows pointing us here to go to one of these two green rectangles.
So maybe we'll have a look at this in the next video.
What's going on here.
What if ridge regression wasn't working at the moment it is but we want to kind of improve this score
so we'll check out what we can do with that in the next video.