All righty.
So we've seen how to choose an estimate for a regression problem.
How can we do the same for a classification problem.
Well first of all let's get a data set that is a classification problem.
Back in our midst.
So we want data.
We've already imported this above what we we're just gonna do it again just so we have it says we just
to make sure it's the same.
Heart disease heart disease dot head wonderful.
So again we've seen this dataset before we want to use these columns of patient each row as a patient
so each sample is a patient each column or each feature is a health attribute of that particular patient
and the target 1 or 0 is whether that patient has heart disease or not.
So our model classification predicting something is one thing or another heart disease or not.
That's what we need.
So what we're going to do is we left ourselves this little link here to go visit the maps we're going
to pay attention to that we go here so we know we want something in the classification realm but what
we're going to do is we're gonna start from the top and follow this through.
So start do we have above 50 samples.
Well let's check each round with a sample so we want Len heart disease 303.
Yes we can.
Are we predicting category.
Are we heart disease or not heart disease.
Sounds like a category to me.
Yes.
Do we have label data.
Yes.
Do we have under 100 k samples.
Yes.
What is this.
We reach a little green box.
Beautiful.
So remember the green boxes are estimated as or machine learning algorithms.
So let's have a look.
This is telling us our problems classification and maybe the first one we come to is trying a linear
as we see.
All right classification SBC and Linnea SBC a class is capable of performing multicast classification
on a data set.
Well this one particularly said linear SBC.
So let's have a look.
Linear Support Vector classification similar to SBC with parameter kernel linear but implement in terms
of live linear rather than lib SVM.
That's a lot of times and most of my I don't really understand.
But what what's important here is that if we go down to the code example we can see from S.K. learned
on SVM import linear SPC x y oh they've used x and y CSF classifier equals linear as we.
All right.
This is kind of similar.
Well let's not take the documentations word for it let's try it for ourselves.
We'll go import actually we'll leave ourselves a note consulting the map and it says to try Linnea SABC
so that will be our first port of call in Port Linnea as we see estimated class we go from SBA loan
SVM and really what I'm doing here is I'm basically just gonna rewrite this spot for our problem.
So SBA loan but SVM important in the SABC import Linnea SABC wonderful set up random seed and paid out
random dot seed and we'll use our faithful 42.
And then we're gonna go make the data.
We saw this in the previous section section 1 Get your data ready.
X equals heart disease dot drop.
I want to get rid of the target column on axis equals 1 and Y equals heart disease Y is actually the
target column.
Beautiful.
And then when you go split the data x test or no train comes first.
So he may have done this about 100 times now and still getting it wrong.
See this is what it takes it takes a little bit of practice or it takes a lot of practice to start applying
stop becoming machine learning practitioner knowing how to deal with data knowing how to split data
knowing how to model data.
It's all part of the practice test songs.
Yes that is correct.
That's what we want to do instantiate linear SBC.
So we call it C.L. short for classifier Linnea SABC and we're gonna go.
That'll do actually say a left not fit.
We want X train y train and then we're gonna go evaluate linear and say C a left on score x test y test.
All right beautiful let's say this in action.
Wonderful linear fail to converge.
Increase the number of iterations.
Well this is one of those things where if you came into an error like this what I might do is go convergence
warning I google this message and see what came up because I've had a little bit of experience with
it.
I might do something like Max it equals a thousand and it still happens.
Right.
So increase the number of iterations.
We've done that.
We've gone Max it equals a thousand but this is actually how much does it start Max iteration or is
default by a thousand.
Let's say 10000 still there.
Well let's bypass that for the time being we're getting a warning and see here the score is below point
five.
Now why is that a trigger in our heads.
Well because if we look at our data we want heart disease target don't value Kant's
so we say there's only two classes 1 0 0 does someone have heart disease or not.
Right so it's a binary classification problem binary meaning one or the other and our model is receiving
a score of point four seven returns the mean accuracy on a given test date and labels.
As I said we'll look into evaluation metrics in in a future section.
But what you can imagine this is our model is only operating at 47 per cent accuracy.
And why does that trigger us.
Well because there's only two classes.
So that means if we were just guessing whether someone had heart disease or not but based off their
health attributes we were just guessing yes or no we would get 50 per cent it's basically a coin toss.
So what's that triggering in a head and saying hey without fixing this warning or without improving
our model by choosing the hyper parameters our linear SPC model might not be finding patterns between
x and y.
So what can we do.
Well when in doubt come back to the graphic not working.
Are we working with test data because we just tried linear as we say so we're going to say not working.
We were going to test data no.
Is going to say caner is neighbors classifier but I'm going to skip this one I'm going to go to ensemble
classifiers.
So let's click on this.
Now why this.
Because we've seen this before ensemble methods forest of randomize trees S.K. lone ensemble from S.K.
lone ensemble import random forest classifier.
Now if you remember back up in our regression problem when we switched to using a random forest aggressor
we saw a bump in the score well because random forests regressive did so well.
Good news is for us it's got a dance partner called random forest classifier.
We've actually seen this before.
But what we're going to do is compare it to linear SPC so to save time I'm going to copy this code and
I'm gonna bring it down here.
So we want to change this to random forest classifier we actually want ensemble import random forest
classifier wonderful.
We can keep the rest the same except for this we need to actually sub this and random forest classifier
and we want to get random forest classifier wonderful we'll do the same here just to tidy up our notes
keep our code communicated.
Wonderful.
And now what do you think will happen here 3 to 1.
Let's see error fit missing one argument why oh there we go.
That's what we've forgotten.
Forgot to add a little brackets on the end.
Wonderful No to get rid of this warning we need to change an estimate as I could see here the default
value of any estimate is will change from 10 inversion zero point two to 100.
So we'll just get rid of that by changing an estimate as equals 100 delicious wonderful.
So what's happened here.
We've used a different model now linear SBC has scored 47 percent accuracy and our random forest classifier
has scored 85 percent accuracy so nearly nearly double by just using another model.
Right.
So you can see why I'm kind of jumping to using random forest if we go back all I've done is I've gone
start I figured out what kind of problem we're trying to solve.
You can do this as well.
So for our regression problem we were trying to figure out whether something was a number for our classification
problem we're trying to predict a label.
Do we have label data.
Yes.
Are we producing category.
Yes.
And now Alinea S.E.C. model wasn't working so we went straight to ensemble classifiers.
And now you might be thinking what about all the other models right.
So we've kind of skipped all these ones here.
All of these and we've only really touched the surface we've only used this one an ensemble classifiers
from both.
And that's a great question.
Well the first reason is namely for time we could go through and try all of these.
And the second reason is there's a little tidbit in machine learning.
If you have structured data a.k.a. tables or data frames use ensemble methods such as random forest.
Why.
Because it'll perform pretty well.
If there are patterns this is a tidbit here.
Heart disease might write this down so we know I'll put this in a resources section as well.
To is one if you have structured data use ensemble methods and two is if you have unstructured data
use deep learning or transfer learning.
Now what's an example of structured data.
While stuff in a table like this and if we have unstructured data which is like images audio or text
or something like that use deep learning or transfer learning.
Now we haven't covered deep learning and transfer learning yet but since we have structured data a.k.a.
things in a data frame that Tibetan his use ensemble methods which is hence why we've kind of gone you
know what I'm not going to try any of these I'm going straight to ensemble classifiers straight to the
random for us because the random forest is known for its robustness and ability to find patterns.
Now who we've covered a lot we've had to look at these machine learning map if we're still looking at
this going Holy gosh what's going on.
Don't worry.
It took me a while to figure it out too but it really clicked once I realized hold on the first step
is to just get the data figure out the main problem we're trying to solve.
Usually regression of classification they're the two most common ones you come across and then start
answering the questions going through it and then use a little framework something as simple as this
to start running machine learning estimate or machine learning model on your data and getting some feedback
from it quickly.
That's the most important part being a data scientist or machine learning engineer is reducing the time
between your experiments.
So what we're gonna do now is we've seen how to choose a model.
We're gonna get into the next section which is fitting a model to the data and then using it to make
predictions because that's really the essence of machine learning right.
Finding patterns in data and then using those patterns to make predictions on future data.
A model hasn't seen before.
Take a quick break and I'll see you in the next video.