OK so we've seen how to make predictions using our train machine learning model and the predict function.
Now let's have a look at how we can use a predict probe a function most distinctly.
What exactly is the predict proto function.
Now what we might do is I might move this comment into a markdown cell because this will make a little
bit more sense and that is a function.
So that's going to get bad and then we're going to go here and predict probe returns
probabilities
probabilities of a classification label.
Don't take my word for it.
Let's have a look at the psychic loan documentation because this is good practice.
So I can't learn predict probe.
There we go here.
We won't predict probe but probability estimates the returned estimates for all classes are ordered
by the label of classes.
OK so probability estimates.
Mm hmm.
What does that mean.
Scratches bead majestically.
Let's have a look.
Run the code first predict probe.
What does it take if we go back to here.
It takes X.
All right.
So that's what we can do takes X maybe we'll pass it the test data just like we did with predict while
we get a lot maybe we only want to do the first five okay.
So predict private returns a probability of a classification label.
Now in psychic line they've used the return estimates for all classes.
So a class would be not heart disease.
And the other class would be heart disease.
So that's just another word for different labels classes.
Now what do we have here.
Well we have probability estimates.
Now what exactly is this.
Let's predict on the same data.
So it's probably easier to understand in contrast when we use just the normal predict function and we
want the first five or test all right.
So returns the probabilities of a classification label.
That's what we got here.
So if we look let's line up this predict private returns an array of five different samples.
Right.
So five this mega array here the two and braces here contain five smaller arrays.
Because we've used five here using slicing and side as but within this array here there's five arrays
of two numbers.
But this only has one array of five numbers.
Mm hmm.
What's happening here.
Well this is what it means by returns the probabilities of a classification label.
So if we look at this let's line up sample one or sample zero with this first array we can see that
the number on the left a.k.a. zero point eight nine is far greater than zero point 1 1.
All right.
Now let's see if there's a trend.
Here we go to here index 1 the label the value on the right is bigger.
And now this is a one.
Now if we go to index 2 a.k.a. label 1.
OK.
The value on the right is bigger again.
So that's index 1 of this array.
And then we've got zero.
This value is bigger.
And then again for the final one it's value 1 and the value at index 1 is greater.
Mm hmm.
So what this is is it's making predictions on the same data but instead of just returning the label
it's returning the probability of that label being true.
So remember our labels are 0 and 1.
So if we go here heart disease target and we want value counts so we've got one for heart disease and
zero for not heart disease.
So what predict probe or is doing is going hey I'm looking at the first five rows of these so x test
I'm looking at these samples.
What I've learned on the training data if I look at this sample here I'm giving it labels zero so not
heart disease and I'm predicting that label zero with a probability of zero point eight nine.
And so if we added these two together the maximum probability you can get is one.
So zero point eight nine plus zero point one one and then if we did the same for the next one zero point
four nine plus zero point five one in kind of get the point there right one one that's a maximum probability.
So what it's saying is that this sample has a zero point eight nine probability of the label being zero.
And the next sample here which gets the label 1 has a point 5 1 2 slightly only just slightly does that
have a probability of being label 1 so that's why it's assigned one woman called predict we force the
model to give us back one label.
So this is where predict probe comes in handy.
Right.
We want to figure out the probability that our sample is given a certain label.
So this one here is basically a coin toss and it's almost 50/50 but the model you could probably say
is pretty confident on this sample this one here being zero because it's 89 versus point 1 1 the same
one for here.
Right.
So this is number three the third index is given zero.
We see this one here.
So it's pretty damn confident that this one is not heart disease as well.
So that's a difference between predict and predict probe.
Is that if we did have more than two classes here.
So if we had like 10 labels if you called predict probe on it you'd get values probability value for
each of those classes that we had but because we only have to we're getting it back a raise of two samples
here.
And so the threshold because we have two samples is whichever one has over point five.
So this is why this one has point over point five and it gets assigned a label of one.
Same with the next one.
And this one has over point five.
So it gets assigned a label of zero which is the index of this array here.
And then finally for this one it gets assigned a label of one because this one is over point five where
the value of point eight to where could you use predict probiotic or maybe in the in the future.
Right you're working on this kind of project you want to make sure that your model is very confident
say we're deploying this to production right we're using this in a hospital and we don't want our model
to give us samples that only have probability estimate of point 5 1.
We want to go hey model only give us the samples.
So this is where we could use predict probe to only give us the samples that are maybe even high and
then point eight nine maybe we only want when our model is extremely confident and then we'll use that
prediction or maybe it is helpful to know which samples are our models not sure about then maybe we
could look at that sample and go hey why is that sample why is this row why is the model unclear about
that is there something we could fix up.
So that's sort of the value there between predict and predict probe to predict we'll give you a single
label for each sample whereas predict probe the returns the probabilities of a classification label
and remember the maximum value here is if you add these up is one.
So the closer to 1 the more inverted commas.
Sure your model is that the prediction it's made is a certain class.
All right.
So now we've seen the two main main ways of making predictions using a classification model I want you
to have a thing.
How can we make predictions using a regression model to revisit if you would go back up and look at
our regression model code.
How can we make a prediction using our regression model and say if we wanted to predict on our Boston
housing dataset the median house price given a row and different characteristics about a town I'll challenge
you to that maybe you'll figure it out before the next video.
But otherwise we'll have a look at it then.