In the last video, we learned how to create our logistic regression model.
In this lecture, we will see how to predict the values of why and how to create a confusion matrix
from those predicted values to get the predicted values from our model.
We just have to right not predict Kiewa to get the probability output from our model.
We have to right.
Predict underscore prob a.
So my model variable is VLF underscore Elat.
Therefore, I would like to see a live underscore la dot project underscore Proby and then in record,
I have to mention the independent variables on which I want to predict the probabilities.
If I done this.
The output is in the form of a ray.
The first column here is the probability of zero.
That is probability of not sought in the second column.
Here is the probability of one that this probability of solid.
If you add these two column, the resultant is one.
So for the first throw, the probability of homes being sold is zero point eighty seven for the second
record.
The probability is zero point six three and so on.
Now, as we discussed earlier, we want to set a boundary condition on classifying it as not sold or
sold by default or want to condition this point five.
Which means that if the probability is less than point five, we had seen that the House cannot be sold
within three months if the probability is greater than parfait.
We are saying that we will be able to solve the holes in three months.
Now, as we discussed earlier, that the cost associated with false positive and false negative is different
and therefore we may want to choose a different boundary condition.
We will use these probability values to choose that boundary condition.
But before that, we will see how to predict zero one or classes depending on point five as our boundary
condition.
So by default, the predicate function that they see L.F. underscore allowed but predict takes boundary
condition as zero point five.
So if I run this code.
You can see we have zero one zero one, the output result resultant is not in the form of problem readings,
but it is in the form of classes that is sort of NORAD.
If you compare from our probabilities values, for the first record, our probability was zero point
eight seven six zero point eight seven is greater than zero point five.
We are getting one for the second record.
The probability is zero point six three.
And since this is more than zero point five, we are getting one.
And the second record as well.
If you look at the third record, the probability here is zero point zero two.
Since this is less than zero point five.
We are getting zero in the third record
now to set custom boundaries condition.
We will use this project to underscore grade a probability values.
So if you see here I am using this product, underscore Proby.
Then I am selecting the second column from this.
That's why I have written one here.
So all the rules and on the second column, then I'm comparing this second column values with point
three, point three.
Here is my board recommendation.
So if the value is greater than zero point three, the output will be crucial.
And if the value here of probability is less than zero point three.
The output will be false.
And I am saving this value.
And why underscore pride underscore zero point three if I rent this call?
And get a sample of my wife tried to zero through and use.
You can see I'm getting this grool for that Spruill false values, depending on the condition I have
mentioned.
Crew means one and false means zero one zero Stainforth, sorry or sorry.
Now we have the actual values of way and the predicted values of way.
Now we want to compare the accuracy of photo model, which means how many times we are actually predicting
the correct outcome and how many times we are predicting the wrong outcome.
Correct outcome means.
Group positives that mean the actual value is true.
That is one and the predicted value is also crucial.
That is one or two negatives.
That is actual value is zero and the predicted value is also zero.
The wrong outcomes are false positive and false negative.
We have already covered this in order to re-elect our.
We also got word confusion metrics to categorize these four categories, and we will draw that confusion
metrics from this output of our model.
To create confusion metrics, we first have to import the confusion metrics.
We will import it from a skill and dot matrix.
And then we'll use confusion, make X function.
There are two arguments here.
First one is the actual values of Y.
And second one is the predicted values of way.
Remember, we created Widespread with zero point five.
That is before it as our boundary condition.
So let's run this.
Here, these rules are the actual classes.
So first rule is four zero.
And second rule is for one.
These are the actual outcomes.
Rules are for actual outcomes.
And this columns are for predicted classes.
So the first column is for zero and the second column is for one.
This one ninety five cents for zero and zero.
That means the actual value was also zero.
That is not sold.
And the third there was also zero.
That is not sold.
These are also known as crude negatives.
This 81 isn't the zero through the actual value of this, 81 was zero, but the predicted value is one.
Since this are in the second volume, these are known as false positives.
This 77 are in the second row.
That is actually they belong to the second class that is sold.
But we predicted them as not sold.
So these are false negatives.
This 153.
For one and one, that is, the actual values also soared and the predicted value is also solid.
Now let's create contingent metrics for our second pretty good value where we use zero point three as
our boundary condition.
Let's run this.
Here is the confusion metrics for the zero point three as overblown to condition.
Now, since we are using zero point three as bond recognition as compared to zero point five year,
that means we are categorizing more values and the one category since we are lowering our probably be
threshold.
So, for example, if for some record the problem is zero point four, if we are losing zero point five
threshold, we are categorizing it as not sold.
But in this case we are categorizing it as sold.
That's why the numbers here are inflated in the second column.
The predicted ones numbers are inflated.
So you can see our false positive values have increased from 81 to 154 and the false negative values
as decreased from 77 to 17.
So if you have different costs associated with your false positive and false negative, you can change
this threshold level to change their distribution of these values in these two categories.