Current location: Homepage > rust > Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep24

Artificial Intelligence Full Course _ Artificial Intelligence Tutorial for Beginners _ Edureka [DownSub.com](1).txt - Ep24

2025-07-11 11:31:21 [web3] Source: ByteGenius
verydevice that's why you have science vs conspiracyto scale yourdata in such a way that all of thesevalues will have a similar range rightso that's exactly what the scalerfunction does okay now since we havealready divided our data into trainingand testing data our next step is tobuild the model right so first we'regoing to be using the logisticregression algorithm right I alreadydiscussed logistic regression with youall it's a classification algorithmwhich is basically used to predict theoutcome of a categorical variable rightso we already have the logisticregression class in Python all you haveto do is you have to give an instancefor this function which is log reg overhere and I'm fitting this instance withthe training data set meaning that I'mrunning the algorithm with the trainingdata set once you do that you cancalculate the accuracy by using thisfunction so here I'm calculating theaccuracy on the training data set and onthe testing data set set okay so let'slook at the output of this now guysignore this future warning rightwarnings are ignored in Python nowaccuracy of the logistic regressionclassifier on the training data set isaround 70% which is pretty good on thetraining data set but when it comes toclassifying on the test data set it'sonly 40% right which is not that goodfor a classifier now again this candepend on the problem statement rightfor which problem statement is logisticregression more suitable right nextwe'll do the same thing using thedecision tree so again we'll just callthe decision tree function and we'll fitit with a training data set we'llcalculate the accuracy of the decisionTree on the training and the testingdata set so if you do that for adecision Tree on the training data setyou get a 100% accuracy right but on thetesting data set you have around 87% ofaccuracy now this is something that Idiscussed with you all earlier thatdecision trees are very good withtraining data set because of a processknown as overfitting right but when itcomes to classifying the outcome on thetesting data set the accuracy reducesnow this is very good compared tologistic regression right for thisproblem statement decision trees worksbetter than logistic regression comingto KNN classifier again all you have todo is you have to call the K neighborclassifierright this function and you have to fitthis with the training data set if youcalculate the accuracy for a Cannclassifier we get a good accuracyactually on the training data set we getan accuracy of 95% and on the testingdata set is 100% that is really goodbecause our testing data set actuallyachieved more of an accuracy than on ourtraining data set right now all of thisdepends on the value of K that you'vechosen for K&N now uh I mentioned thatyou use the elbow method to choose thekey value in the K nearest neighbor I'llbe discussing the elbow method in thenext section right so don't worry if youhaven't understood that yet now we'realso using a knife bi classifier herewe're using a goian knif b classifiergoian is basically a type of knif Bclassifier right I'm not going to gointo depth of this because it'll justextend our session to much more longerokay and if you want to know more aboutthis I'll leave a link in thedescription box you can read all aboutthe caution knif B classifier how themath behind this is the same right it'suses knif bias it uses the bias theoremitself now again we're going to callthis class and then we're going to runour data training data on it right sousing the knif bi classifier we'regetting an accuracy of0.86 on the training data set and on thetesting data set we're getting a 67%accuracyokay now let's do the same thing withsupport Vector machines importing thesupport Vector classifier right andwe're fitting the training data into thealgorithm we're getting a accuracy ofaround 61% on the training data set and33% on the testing data set now guysthis accuracy and all depends also onthe problem statement right it dependson the type of data that support Vectormachines get usually svm is very good onlarge data sets now since we have a verysmall data set over here it's sort ofobvious why the accuracy is so less soGuys these were a couple ofclassification algorithms that I showedyou here now because our KNN classifierclassified our data set more accuratelywe'll look at the predictions that theKNN classifier made okay now we'restoring all our predicted values in thepredict variable now in order to showyou the accuracy of the Cann model we'regoing to use something known as theconfusion Matrix so a confusion Matrixis a table that is often used todescribe the performance of aclassification model so confusion Matrixactually represents a tabularrepresentation of actual versuspredicted values so when you draw aconfusion Matrix on the actual versuspredicted values for the Cann classifierthis is what the confusion Matrix lookslike now we have four rows over here ifyou see we have four rows the first rowrepresents apples second Mandarin thirdrepresents uh lemons and fourth orangesright so this four value corresponds to0 comma 0 meaning that it was correctlyable to classify all the four applesokay this one value represents one comma1 meaning that a classifier correctlyclassified this as mandrin this madeMatrix is drawn on actual values versuspredicted values now if you look at thesummary of the confusion Matrix you'llget something known as Precision recallF1 score and support Precision isbasically the ratio of the correctlypredicted positive observations to thetotal predicted positive observations sothe correctly predicted positiveobservations are four and there aretotal of four apples in the testing dataset so that's why get a Precision of oneokay so recall on the other hand is aratio of correctly predicted positiveobservations to all the observations inthe class again we've correctlyclassified four apples and there aretotal of four apples F1 score is nothingbut the weighted average of yourpresision and your recall okay and yoursupport basically denotes the number ofdata points that were correctlyclassified so in our KNN algorithm sincewe got 100% accuracy all our data pointswere correctly classified so 15 out of15 were correctly classified because wehave a 100% accuracy so that's how youread a confusion Matrix okay you havefour important measures Precision recallF1

(Editor: go)

Recommended articles
Hot reading