‫Welcome back.
‫In the last video, we finished off checking out our correlation matrix and we looked at our workflow
‫and saw that we're now up to step five.
‫So we've covered problem definition, data evaluation, we've looked at the features, we've done a
‫little bit of data analysis.
‫Now it's time to start bringing in machine learning.
‫So let's see how we do that.
‫Let's go into here.
‫We'll create a little heading.
‫It might do it 5.0 modeling.
‫And we're going to turn this into markdown.
‫And so what's our problem?
‫So let's scroll back up.
‫We defined it up here.
‫Right back at the start.
‫So problem definition is step one.
‫So in a statement, given clinical parameters about a patient, can we predict whether or not they have
‫heart disease?
‫So we're working with a classification problem.
‫Okay.
‫That's what we're trying to be answering with machine learning and evaluation.
‫So this is our evaluation metric because right now we've got a data set and we're kind of we're just
‫exploring it.
‫We're experimenting here.
‫So if we wanted to actually get this into production, into a real life setting, we'd probably want
‫it to be fairly good, right?
‫Because it's predicting something as important as whether someone or not has heart disease.
‫So we would want a minimum of 95% accuracy at predicting whether or not a patient has heart disease
‫during our proof of concept, which is kind of what we're working through here, and if we can make
‫it to that, we'll keep pursuing it.
‫We'll keep going, see if we can improve it, make it better, or see what we need to improve.
‫So this is what we're going to be trying to solve with machine learning.
‫We're trying to answer this problem statement and this is our valuation metric, something that we'll
‫be working towards.
‫And of course each of these could change, but these are just give us a little roadmap or something
‫we can head towards.
‫So let's go down, see what we would do.
‫The first thing we might do is relook at our our data set, remind ourselves of what we're doing.
‫So we're going to be using these columns.
‫To try and predict the target column so a.k.a the independent variables to predict the dependent variable
‫here.
‫And the first thing we might do is split our data into X and Y, so we'll split it into features and
‫labels.
‫And then what we might do is create a training and test split similar to what we did in the psychic
‫loan section where we work through the cyclone machine learning workflow.
‫So let's do that.
‫So let's go split data into X and Y.
‫X is going to be equal to every column except the target column.
‫That's what we want.
‫So def drop.
‫We're going to drop the target.
‫We're going to set the axis equal to one.
‫Beautiful.
‫And then y is going to be these are all the labels.
‫So we're going to go def.
‫We can just go target.
‫There we go.
‫Now let's visualize X.
‫Wonderful.
‫No Target column and we'll visualize why to remind ourselves it's just zero one whether or not someone
‫has heart disease.
‫So it's a binary classification because there's only two options binary meaning zero or one.
‫And now what we have to do is split our data into a training and test one.
‫Now, we've seen this before, but it's worth reiterating.
‫Why not use all the data to train a model?
‫What is a train and test split?
‫Well, let's say you wanted to take your model into the hospital and start using it on patients.
‫How would you know how well your model goes on a new patient not included in the original full data
‫set that we have.
‫So if we built a model on every single sample in this this data frame, how would we know?
‫How would we have an insight into seeing how it would go on someone that our model has never seen before?
‫This is where the test set comes in.
‫It's used to mimic taking our model into a real environment as much as possible, or at least it tries
‫to as much as possible.
‫It's important to never let our model learn from a test set.
‫It should only be evaluated on a test set.
‫So we're going to have a training set, which is like when you're studying for an exam, it's like the
‫course material.
‫So the machine learning model is going to learn the patterns in the course material, then it's going
‫to be evaluated on the final exam, which is the test set.
‫So let's see that what we're going to do is split data into train and test sets.
‫So to do so we can use numpy random seed first so we can reproduce our results and we can split our
‫data into train and test sets using psychic learns.
‫Train test split.
‫So we go split into train.
‫And test set.
‫X shrine, x test.
‫We saw a lot of this in the psychic loan section, but it's paramount to reiterate that, that whenever
‫you try to test or whenever you try to evaluate your model, it should be on data that the model has
‫never seen before.
‫Test size.
‫We're going to do the standard 0.2.
‫So this X is what we've created up here, our dependent variable, and this is why, which is our labels.
‫So now we're going to shift and enter.
‫Wonderful.
‫And we're going to have a look at the training data.
‫So we've got X trying.
‫We can see that it's shuffled it and it's go 242 rows out of the total, 303 rows.
‫So it's got about 80% of the entire rows.
‫Then we can do the same with the Y train and we might do find the LAN of y train as well.
‫Y train is the same length as x train.
‫But it's only got the labels.
‫And so if we compared the indexes here, it's got the labels for each of these samples.
‫One, three, two, one, three, two, one, two, four.
‫Now what do we do?
‫Well, now we've got our data into X and Y, we've got train and test as well.
‫So we've got a training data and we've got testing data.
‫The next thing is to build a machine learning model and hmm, well, working with classification.
‫This comes to a point where it's like, what model should we use?
‫Now we've got our data split into training and test sets.
‫It's time to build a machine learning model.
‫We'll try it.
‫So find the patterns on the training set and we'll test it.
‫Use the patents.
‫So using their patent, it's found on the test set.
‫But what machine learning model should we use?
‫Well, if you're a member in the socket loan section, we checked it out.
‫The socket learn machine learning map.
‫So we're going to go in here.
‫Wonderful.
‫So this is our start.
‫So if we follow this through, we know we've seen this before, we've got a classification problem.
‫We're trying to classify whether or not someone has heart disease based on their health parameters,
‫based on their medical parameters.
‫So what we might do is only try a few of these.
‫You could try all of them.
‫But what we're going to try and do is use K neighbors classifier, we'll use this one.
‫So if we open that in a new tab and then we're going to also use our trusty random forest, so we'll
‫open that as well.
‫So ensemble methods is a random forest in here.
‫Random forest.
‫Random forest classifier.
‫That's what we're after.
‫Yes.
‫Beautiful.
‫And we got here the nearest neighbors.
‫Wonderful.
‫So if we look through that, we'd see how we could use it.
‫But we're going to see this in practice.
‫But there's one more.
‫If we go back here, back to our machine learning map and it's not listed on here.
‫Hmm.
‫I wonder why that is.
‫Well, we're going to see it in the next video.
‫What it is, I'll give you a little clue.
‫It's called logistic regression.
‫And you might be thinking, hey, we're working on a classification problem.
‫Logistic regression has the word regression in it.
‫And why isn't it in this classification part?
‫Well, that's a great question because I'm not really sure either.
‫But we're going to have a look at those three models in the next video.
‫So we'll create them and we'll see how each of them goes.
‫Because remember, we're experimenting now where in our modeling slash experiments phase.
‫And one part of the experiments phase is trying different machine learning models.
‫So that's what we're going to do.
‫We're going to try three different machine learning models and see how they compare with their results
‫on the test set.
‫And then of course, we want the best one, so let's do that.