In this session, we will be discussing about the implementation of Chian, so let's have a look at
this.
So for this particular implementation, I have faith feed my indians'.
Diabetes does it.
So let us start with importing the required libraries.
So the importance libraries are no Fondas and my.
Next, we will load the data set for loading the data set, we will again use the dock re CSP, which
will allow us to read the CSC fight the CSP files there.
These are CSFI and there is no specific different delimiter.
So that is why we are not giving any delimiter here and here.
We have the data from the.
Now we will be printing the first five rows of the data.
So here we have the first five rows of data from which we have printed using the dotted.
Now, the columns I pregnancy's glucose, blood pressure, skin thickness, insulin, BMI, diabetes,
videgaray function, age and outcome.
Here outcome one person that the person has diabetes and outcome zero represents that the person does
not have diabetes.
So now we will check the shape of the data frame.
So the shape of the data frame is seven.
Sixty eight, Guama nine.
This we have obtained for using the shape attribute.
So the shape gives the shape of the data frame the seven sixty eight point nine.
Now we will check that we have to do seven sixty eight rows, nine columns.
And out of these nine columns, the first eight columns are the features that this these first columns
are the features and the last column is the Thugged or the label value which we want to predict.
So we will create No by Eddie for features and targets, so the fullest Eddie will be ex and the second
will be via X will contain the.
X values, that is from pregnancy's to each and Y will contain the outcomes.
How we do that, we simply beg the veto threat and if we will drop the outcome from this, we will get
all of these columns except the outcome.
So that is what we do here.
We do the don't drop the column name and the axis Rumbo axis Zettl stands for Raus and Axis one stands
for columns.
And then we find out the values using DOT values.
So we are getting all the values from the data from.
And after dropping the outcomes from this, now, Vivi will be having only the outcome.
So we are doing the outcome and hopefully we could have taken the data from itself also by doing the
proper outcome while my ex is one and the.
With the outcome, but this is like another way.
So there are two ways how we can do it.
So it is completely up to you if you want to get a Bayati or you want to get the delphiniums.
Now we will split the data into training and testing data set.
So let us split it using the brain split so we will import the brain split from Ascalon lot more this
election.
So from this election we are importing festering split and we will get split the data.
Now, here I am splitting the data with this size equal to zero point for.
And here I am, having started this fight right now, we have given random state to be 42.
You can give any random state based on your convenience.
I these are the values which we will be getting from this.
So the X will be divided into extreme and X test and the Y will be divided into vibrant and whitest.
Now, let's create a classified using dangerous neighborhood algorithm.
So first, let us observe the accuracy for different values of now what case?
The number of nearest neighbors.
OK, so we what we will do, we will import the nearest neighbors, classify it from the Escalon neighbors.
Now they will set up the area to store the training and the testing accuracy, so we have created this
at a neighbour's.
Which has values from one to nine.
Now, we were creating.
I've won it as drin accuracy and another area as best accuracy.
Now they are running value.
On the values of think, that is on the values of the.
Neighbors which will be enumerated so basically on all the neighbors, the.
Running this particular.
Now we are creating an object of the cannon classify it.
And in this object, we are putting the number of brzeski, so each time it will keep running the loop
and it will change the number of neighbors from one do it, all the values will be taken in this case.
Now, the other thing, the model using, again, is not fit and giving in the extreme, and rightly
so.
It belongs on the extreme and vibrant values.
And after the food is done, we can get the cocaine in school, so for in school, we're running the
values from ecstasy and victory and we are getting the training accuracy from this eye for testing accuracy.
We are running it on its best and brightest.
Now, from this, we have obtained these two areas which have been accuracy and testing accuracy.
So now we will create the lot to actually visualize what we have obtained from this train accuracy and
the best deputies.
Now we can see that this blog title we have given game, nearest neighbor, varying number of neighbors,
the plot has two lines.
So the first line is from the accuracy and the second line is from the three inaccuracy.
And we have created a legend, provided the exlibris and vibe when we are printing the Lord, we are
able to see these two lines generated.
Now, when you see the training, accuracy is decreasing as the number of members increase.
And the testing accuracy is actually increasing slowly.
And if we compare the values.
These values increased in the number seven, number seven is the point where these accuracy's are closest
and the best accuracy is pleasing.
And after seven, the best accuracy actually starts to go down.
So this is the reason why we will select seven as the number of neighbors.
So we can observe that we get maximum testing accuracy for people to seven, so we will create the dangerous
classifier with a number of neighbors, that's seven.
So how will we do that?
We will meet again another object of neighbors.
And this time, we will provide the number of neighbors s7 in this object.
We will provide the extreme and vitrine and then fit the model.
Now, when we put the models, the model will learn from this data.
And after learning from this data, we get the Cannon School.
This Ganin score comes out to be zero point seven three zero.
Now, next is creating a confusion matrix now of confusion matrix, is it a move that is often used
to describe the performance of a classification model on a set of test data for which the true values
are already known?
So Escalon provides the facility to calculate the confusion matrix using the confusion matrix method.
So that is what we will be using here.
So what is the confusion matrix?
We are importing the confusion matrix using Escalon, dot matrix.
Remember Escalon, Dot Matrix holds all the different types of matrix which we can use for evaluating
our models.
So always keep exploring these metrics and comparing different matrix.
Use a lot of matrix and compare the models using these matrix and see which metric actually works well
for you.
Then let us give the prediction.
So far, the predictions we are simply using can not predict on X this data and then we have the predictions
from the best data.
Now, we already have the very values and now we have generated divided values by using can and predict.
So we are predicting the values on the X test values.
We already have X values, so we predict the values for these X best values using the model which we
have generated and we get the predicted values.
Now we compare these Y predicted values with the widest value which we already have and in the confusion
matrix.
So this confusion matrix give these, Eddie.
Which is basically true, negative as one sixty five.
Proof positive as 60.
False positive as 46 and false negative as forty seven.
We can also obtain the confusion matrix using the crosstab method, so we can simply say we don't crosstab
and provide Vytas here, then why predict in the role we will give the true value and in the column
we will provide the predicted value.
So this way we will get predicted.
Zero one zero zero one, so Ventoux is zero, it is false, Ventoux is one, it is true I.
This is true, this is false, and so we can decide it accordingly.
So we have classification report, which is another matter, which is a textual summary of the precision
recall, if one school for each and every class so we can use it on imported from Eskil on dogmatics.
Now we will generate declassification report on Vytenis and predict now here you can see that the decision
is zero point seven eight four nonminority and zero point six to four day.
But the goal value is zero point eight to one zero point five six.
If one score is zero point zero zero point five, me, I'm supposed value is two hundred and one and
one hundred and seven.
The accuracy at micro level on four weighted average of seventy and seventy three, so these are different
values.
Now we can find the orosco also for this, so what is Orosco again, the sequel is the plot, which
is, if true, positive rate with respect to the false positive rate.
We have discussed this during the time when we discussed the logistic regression.
So it is a plot of the true positive rate against the false positive rate for the different possible
points for a diagnostic test and auto cycle demonstrates several things.
What are those things?
Number one, the rate of between sensitivity and specificity, that is any increase in sensitivity will
be accompanied by a decrease in the specificity.
And the closer the Gulf follows the left hand border and then the border of the SP's, the more accurate
the best is.
Now, the closer the Gulf comes to the 45 degree diagonal, the less accurate the values.
So we want to move it towards the top left corner.
Now, the area under the Gulf is a measure of the accuracy.
What is now we will be making the predictions, we will be predicting the probability using the excess
data and we get the probability to vibrate from.
Now, let us just read the sequel, so again, we will import the sequel from the Eskil or Not Matrix.
Now, here we will have the.
Fear that this false positive debate, the true positive rate and the threshold value.
So we will generate the sequel for Vytenis with the with companies in Dubai predicted probabilities
and we will create the plot for the scene.
So this is the plot which we have created.
And here you can see that the these values are what are good enough.
So this is one value, which is which is a nice value where we have it close to the left side also and
towards the upside.
Now, if you see the area of the Gulf, we can find it using you for.
But just coming out with zero point seventy four five.
Now, this is one method which is using this brain split, but we have used another method, which is
a very good method that is cross-validation.
So let us implement this using cross-validation as well.
So how would we do that?
So we will get the hyper barometer's and we will use the cross-validation.
Now, again, what is false validation?
The PRIMORDIA performance is dependent on how the device splitted.
So instead of using the hold out method, we will use the cross-validation what is called validation.
Cross-validation is a technique to evaluate predictive models by partitioning the original sample into
a training set to train the model and test set to evaluate it.
So we will create key features and then add every time each one will be selected as a distinct field
and other fields will be selected as the training fields.
And that is how we will get those values.
And then we can average them out, then find the final validation.
So we will be doing hypovolemic for this now, we have already selected the value of, but now we want
to find out the optimal value of using hypovolemic.
So for this, we will try some different hypovolemic, those values and then sort them all separately
to the model, and then we will choose the best one out of this.
So we will use TV for this, which we have already built on great TV.
So how does it work?
We will create the bottom three in this forum, great, we are giving the neighbors as the barometer
and the values are ranging from one to 50.
Now we are creating an object of canibus classifier and we are creating an object of great TV which
has the model, which is Ganin and the Bottom Great and the C.V, that is the cross validation for number.
That is five foot.
Now, the feeding the data into it, so we have it X and Y it.
After four X and Y, we have found out the best score.
Is zero point seven five seven eight and the best barometer is anybody's guess 40.
So this is what we have or been that is we have found almost seventy six percent accuracy using the
neighbors numbers 14.
And what is really what we have found out was seven.
So here we have improved the accuracy by almost three percent using the grid to a TV and by selecting
the higher number of neighbors.
So next, we will learn about the next algorithm in the next session.