‫Now the magic really starts to begin.
‫And I'm very excited for this because why?
‫This is what we've been building up to.
‫We've been training.
‫We've been doing a whole bunch of code.
‫We've been working with data, we've been filling missing data, we've been turning it into numbers.
‫We've been training countless machine learning models.
‫Well, actually, probably about five or six in this notebook.
‫But now we're finally going to use a trained machine learning model to make some predictions.
‫This is where the magic in machine learning really comes down to, right?
‫So what we're going to do is we're going to take our model here, the one that we've trained.
‫We can run this again.
‫So this is going to give us a score here.
‫So this is training CLF on the heart disease data set the X telling our model to find the patterns between
‫X train and Y train.
‫Now what we're going to do, we've seen C score.
‫Now this is evaluating the model on the test data set so data it hasn't seen before.
‫So really what's going on behind the scenes with score is that the model is making predictions on the
‫X Test data, actually making something like Y spreads and then comparing them to Y test.
‫Spoiler alert, we actually kind of have been making predictions, but now we're going to see them in
‫the flesh.
‫So let's go here.
‫All right.
‫A comment.
‫Use a trained model to make predictions.
‫Now, there's two ways real ways to make predictions with two ways to make predictions we want to use.
‫One is the predict function.
‫Actually, there's a few more than this, but these are the main ones predict function and then two
‫is predict proba.
‫I'm going to look at predict first because this is the main one you want to use.
‫How can we do this?
‫Well, the beautiful thing is because of the beauty of the psychic loan API.
‫Right?
‫It's been designed amazingly so kind of when you do one thing, that's why we could so easily sub out
‫our model before linear speak for random forest classifier.
‫Almost no matter what model we have here, there will be some kind of fit function, a score function
‫to evaluate it and a predict function so naturally let's try call self, don't predict.
‫Now what do you think predict might need to take if we were trying to make predictions here.
‫Trying to predict whether or not someone had heart disease.
‫What should we get our model to predict on?
‫The important thing here is to remember what is our model learned on.
‫And in our case, it's learned on these features.
‫It's learned on these different body parameters or health parameters of a patient.
‫And so it makes sense that predict function.
‫In order for our machine learning model to make a prediction, it has to be passed.
‫Similar data, actually the exact same data or same format of data that it has learned on.
‫So let's give an example.
‫If this doesn't work, we'll make one that doesn't work to begin with and p dot array and put some random
‫stuff in here.
‫1784 actually three four.
‫I was looking at four but press anyway.
‫Long story.
‫Short shift into this doesn't work.
‫Hmm.
‫Why is that value error?
‫Let's go down here.
‫Expected 2d array but got one D array instead.
‫It showed us our array.
‫We put in there.
‫Reshape your data using either array.
‫Reshape if your data has a single feature or a rate, or reshape one negative one if it contains a single
‫sample.
‫But what we can do, we have some data in the correct shape already and that's in the form of X test.
‫So let's see.
‫Let's remind ourselves before we pull the trigger, the shape of X test, because remember, our model
‫has trained on the training data and it has never seen the test data before.
‫So if we want to make predictions, it has to be in this shape.
‫So let's do it.
‫Aha.
‫What does this look like?
‫What does this remind you of when we're making predictions here?
‫Maybe not too much because it's just an array of zeros and ones and that's alright if you're thinking
‫that.
‫But if we have a look at why test.
‫We've actually got the exact same thing.
‫Maybe if we go and be a ray, see if it'll format in the exact same way.
‫Boom.
‫There we go.
‫So now what we've done is we've made predictions on the test data to predict whether someone or not
‫has heart disease.
‫So zero or one.
‫Now, our labels are in the same format as our test labels, so our predictions are in the same format
‫as our test labels.
‫Now that's a bit of a mouthful, but you'll see why this is important.
‫So now we can compare the predictions to the truth.
‫In our case, this is the truth.
‫Right.
‫The test labels, this is where we split our data set up above here.
‫We split it here.
‫And these are our predictions.
‫So this will make a little bit more sense here once we put it in code.
‫So compare predictions to truth labels to evaluate the model.
‫It's kind of good practice to save predictions to something like y spreads.
‫This is what you might see in documentation.
‫Clf predict x test and now what we're going to do is NP mean y spreads equals y test.
‫Boom.
‫So now what are we doing here?
‫We're making predictions here with our model, and we're comparing the predictions to the ground truth
‫labels.
‫And actually, I'm using a different word here.
‫Ground truth.
‫That's another name for why.
‫So I'm comparing it to the truth labels from our original data set.
‫Take that down.
‫Why is also referred to as ground truth.
‫Maybe I should have put that up there with our nomenclature.
‫But where does this number remind us from?
‫Well, where does this come from before?
‫So we're going to see ll f score, x test, y test.
‫They're the exact same thing.
‫Beautiful.
‫So what we're calculating here is the accuracy or just comparing how well the model did with this map
‫mean we're going, hey, for each sample in here, did our model actually predict that label so we can
‫go through it manually and go, zero zero yep.
‫One.
‫I got that one wrong.
‫Got that one right.
‫You got that one right.
‫Got that one right.
‫And we could go on that you could imagine if you had thousands and thousands of different labels.
‫So we're not going to do that manually as if we would ever do that.
‫There's one more way of doing this.
‫We can go from Skyline Metrics, import accuracy, score.
‫Again, we'll cover metrics in in.
‫I think it's the next section we're getting ahead of ourselves.
‫I was about to check what we're covering.
‫We might do that now.
‫Yeah.
‫Evaluating a model is the next section, but for now, just check it out here.
‫Accuracy Score.
‫Why Test Y spreads now?
‫What do you think this will come up with if we're checking the accuracy score, if we go back here and
‫press shift tab returns the mean accuracy on the given test data and labels.
‫So now we run this boom, same thing.
‫So three different ways here of doing the exact same thing if we go here.
‫Why?
‫True.
‫See, that's where I got the true name from, right?
‫The ground truth.
‫In our case, our Y true labels or the labels that came with our data set are in the test data and our
‫prediction labels are saved to y spreads.
‫They've used y pred here in the docstring.
‫So this is the accuracy classification score.
‫Beautiful.
‫So that is one way to make predictions with our classification model.
‫So now let's see up here we said there was two different ways predict and predict prober.
‫We'll leave a little comment for ourselves.
‫Make predictions with predict prober.
‫Now, I'm going to say this for the next video, right?
‫To make sure this one doesn't get a bit too long.
‫But otherwise, I'll have a little practice with making some predictions, seeing if you can call the
‫predict function with X data set in the same format as the data that it's trained on.
‫And I'll see you in the next video.