0:00 hi everyone in this tutorial I'm going to explain you the theor theoretical concepts of U DS attack as well as the complete code explanation of the Doos attack classification by Machine learning so before understanding uh the code explanation or doing the code first I would like to explain you what is actually dodos attack or the complete OB observation is denial of services so let's see what it is actually okay so before understanding the concept I would like to show you the
0:46 what is the complete project pipeline what we going to do in complete project from A to Z so our first step is the collection of the data collection of the data actually this this problem this project is a supervised learning machine supervised machine learning project so for so for that we need a data which has uh input and also the label uh Target value or you can say output of the model yeah so I have collected data later on this slides I will show you from where I did collect the data and what kind of features I have in the data okay and how I have splitted the
1:33 data into the testing training okay so first step is to collect the data this one and after that the second step is sorry for that the second step is we will pre-process the data of course the data we will get is that would be really dirty a lot of missing values there are the features would be in uh in different data types we need to convert them we need to convert the categorial English language into in the form of numerical uh if you find any problem like that and also we will convert the the taret column in the form of numerical as well okay uh we will remove the N values is up to you either we remove it we replace it or we will see
2:20 that in the code explanation now after that after pre-processing the data the next step is data analysis and the data analysis section we will explore the data what kind of patterns are in the data and how our data is distributed either it is a normal distributed or not we need to explore it see the data in the form of graphs so after performing the data analysis uh The Next Step that is the data splitting of course before training any model machine learning model we need to train we need to split the data into uh two sections so one section is the training section means the input data we
3:07 will feed to the model to train our model and then one section is for the testing of model to check the accuracy F1 score and different parameters here I have splitted the data into 70% as a training data 30% as a test data but there is no exact number there's no exact thres hold to set the training and testing data but the better is if you keep the maximum data for training like 70% 80% uh you can keep like 65% for training rest of the data for the testing it's up to you and it's up to on your data if you if you have really big data then you have to keep like 65% for
3:55 training a rest of the data for the testing now after splitting the data the next step is to train the model so in this in this tutorial what I'm going to do is that I'm going to train three machine learning models okay so the first one is the random Forest that's the machine supervised machine learning model it is actually made of uh collections of disent tre so when when you collect a lot of dis tree that makes it a random Forest so as them suggest you know the forest forest is made of the trees so that's why a rendom forest if you don't have any idea about these algorithms I would suggest you to uh find any tutorial blogs uh to get the
4:43 understanding of these models how they work what kind of mathematical operation at the back of these models okay and then come back to this video in this video I'm not going in the depth of the mathematical operation of these models analysis and desktop of will simply Implement Implement uh that models or train those models in this project okay now after random Forest um I will train the logistic regression then then I'm going to also train the neuron Network so what I will do I will train three models on my data okay and then I will evaluate those models like I will uh if you go to the this step the evaluation
5:29 of the model the green one this one and you can see that what I will do I will test the models on my 30% test data so the test data where this one is my test data I will test on this one and for each model I'm going to calculate the accuracy f one score Precision recall confusion Matrix okay so for each model I will do that and after that I will also calculate the ROC curve of the each model and at the end of three mod models at the end of after testing three models what I will do I will compare these the accuracy of three models with the help of or car okay uh the purpose is to to know which model is best um which model
6:15 is best to classify the the DS attacks from the data okay then uh after that I will select the best model among these three models uh to used on my real data for the classification of DS text so this is the complete pipeline which I'm going to follow collect the data from here till here the classification on the real data okay now let's move forward before going to write the code about the the training models machine learning what is that first need to understand what is actually Doos attack I call it D DS attack um some people pronounce it little bit different but the proper uh OB Rion of that is
7:01 distributed denial of services so what it is let's read the definition so this typically occurs when multiple systems flood the bandwidth or resources of a victim such as such an attack is often the result of multiple compromis systems for example B net flooding the targeted system with generating the huge n traffic in simple way means if you look at the diagram mean that his one attacker okay who's attacking on the victim networks what he is doing he is just is G is generating a huge traffic on the victim Network to make all the system busy okay we dealing with that
7:48 Network and the the attacker is just trying to hang all those systems uh which are in that Network like if it could be MacBook Windows system servers and everything is just sending the the viruses viruses on that Network to make to to create huge traffic in that Network to to hang complete network of the victim so that's actually meaning of that one if you still have any confusion that one just read any definition from Wikipedia or understand uh there are a lot of very good videos about those denial of u tech on the YouTube a lot of uh people they expanded there so you can understand better there now to
8:34 create to train uh the machine learning models okay we need the best data I know that creating machine learning models writing python code is bit easier today in this time where we have the chat GPT and a lot of boots there but the main the main thing is in this project is the data okay I have seen a lot of datas but those datas are really old now at this moment I have tested them I have checked them even I have one more video on my Channel about the Mal deduction you can also view that video so what I have done I have chosen this this uh research paper so This research paper uh it gives the review of all the
9:22 data of the Doos attack if you if you look at the red line here uh there exist a number of such data set such as DARPA 98 kdd99 these are the Mal Doos data sets Okay and these are really huge like in these are in GPS and this research paper towards generating new inion D deduction data set and inion traffic characterization this paper set even you have to search the name of this paper for paper you can search you can find on Google what I will do I will share the link of this paper as well as the link of the data which I'm going to use for this project uh under my video so you can access the data and paper from there okay you can read the uh abstract by yourself I just
10:10 highlighted the important uh information here if I just move forward you can see the data set which I'm going to use in my project so the data set there are some little bit description of the data uh so this guy the paper which I have shown you these authors uh they capture uh they capture some data uh from the from the network where they have faced Some Ds attacks denial of services attack from the hackers so they have captured those kind of attacks and then they stored in this data so when they say they start capturing uh start capturing of the data started at 9 a.m. on Monday July 3rd okay and it ran exact duration for 5 days so it was the whole uh capturing of the data was uh um ran
11:00 for the exact duration of 5 days so it ended on 5 p.m. on Friday July 7th okay that's the duration of capturing of the data from the network and what the important thing is you can read by yourself that's the important thing is this one the red circle you can see this one so it says that the the data is publicly available at this website and you can access the data from there there are there are normally file five files from five different days on the right side you can see that the Monday Tuesday Wednesday Thursday Friday 5 days and they have uh deducting a lot of packets from the network okay so you
11:47 can see that in your data now before uh going forward before mve forward okay let's move to the code explanation from as I told you from this figure from start till end and during that during the explanation of code I will come back to these slides because I have some some images to to teach you better about the model how it works okay what kind of things are there so let's move to the explanation of the code so this is the uh my coding file folder so in this folder I have the main
12:36 file which is the jupyter notebook with extension of that one and I have one more folder which is the data so inside the data if I just double press on it I have the data set I cannot see the data here but I'll will show you the data yeah inside the data uh inside the data folder there's a file which is do. CSV that's my data which I'm going to use to work on this data set okay I go back I have uh already opened this file here so it's running at this moment here so this is my coding file which I'm going to explain you from top to bottom explaining you I'm going to explain
13:21 everything so for that I have created a table of content here uh which shows everything uh from start to end uh like importing libraries data pre-processing and everything till the model comparison okay now before moving to the um code explanation further uh let's let's check the data so as I told you I will put the link in the description of the video uh that link the data link and as well as the this code file which I have put on my GitHub so I will put the link in the video description so let's
14:07 first download the data because the data has a lot of files it has around five to seven files I'm just using only one single file so it's up to you if you want to use that those all files you can use them you can download it from here so let's first download for check it how to download it because it is a bit um uh you have to follow some steps to download the data so when you will copy the link you will come to this page so that's the official page of the that data which is cic C IDs 2017 this the data set you can you can read all the description here from start to end how they have collected the data when
14:52 they have collected the data all the information is given here even if you just look at the left side of the data the research the membership the data set in each and everything is mentioned here that's the actual official website of the data set okay so means the data is really good really informative and you can train any machine learning model or deep learning model on this data now if you look at the size of the data you can see that the Monday normal activity 11g GB Tuesday's data that's the 11g GB actually when ISD th uh okay thus combination of attacks and normal activity 13g Thursday same uh and then I'm using
15:40 this one last one Friday the attacks plus normal activity 8.3g I'm just using I just selected this file there's no um any any main reason to select the data I just picked that file okay now the question is how you can read the further description of the data like Monday Tuesday and everything is mentioned here now if you scroll down and go at the end of the this page this one you will see a a download this data set this this one a link is there if you just press it so it will go it will take you to the new page where you will put your information okay name email organization job title country you will select the country and submit it then
16:26 they will provide you the uh access of this link okay that's the one way to access the data if you want to if you don't want to put that information there I I would suggest you go for this method this is the official one and with this method you can access complete the data if you're going to do a dissertation or any big project you must have to go from this side okay by following that criteria there's one more thing is for you if you if you just want to take the sample of the data uh if you just go to the kaggle and write it there the cic IDS 2017 and there you will see the data set there as well okay so these are the
17:13 three data set uh which are uh published by which are uploaded by these three three authors there's one more improved verion of this one you can also use that one this is 11 GP JP if I just press on this one network intrusion data set okay if I just go down let's check it so it says that the it has all those files here Friday working hours Friday Monday Thursday okay Tuesday and in this way so it has some sample files here which are around 800 uh 84 MB data so that's also quite Big Data you can also use that all the files and combine them what vertically
17:59 you can use you can use this data here okay okay you can use forther I think these three all are same this one is the last one is bit different that's the improved variant of the data so you can also use that one but I would suggest you for that process which I told you this one now let's move to the programming file how to use this data to classify the D do attack malare from Mal from the data so first step is importing the libraries here I have imported the libraries I'm going to take this project um not uh not on expert level I will
18:47 explain you each and everything in a simple way so that you can easily understand it so if you don't have any expertise in uh python machine learning it's okay you will understand understand what I'm saying I will explain you everything an easy way now here first I'm importing the libraries because to use the functions models and evaluation Matrix I need some building functions so for that I need some libraries so I have imported the libraries here so this library is used to deal with the uh files like the comma separated Excel file so I have uploaded I have used that one one NPA is used to deal with the arrays these are the libraries to plot
19:34 the graph on the screen or in a jupyter notebook that's why I'm using the most common one is mat plot Li you you have to import that one if you want more interactive props then you have to use the CBO okay so import CSV you also have to import that one uh for the CSV file now uh further on I will translit the data I need this one for that one I have machine learning model libraries just copy paste this code you don't need to understand at this moment just copy paste them in your notebook and now after that I have some evaluation matric of course I need to evaluate the model
20:19 so for that I need for that I need those uh functions so that's why I'm importing them and this is the same one okay now let's move to the importing the data what I'm doing here I'm saying PD PD was my this Library this one this okay so I have given a nickname to my pandas Library which is PD so I'm here saying here the PD do read CSP it has a one function read CSP and inside that I'm giving the path of my data file okay now if you go back look at that one this is my main file okay in my main file there is one with beside that one I have one folder data so inside the data there is a data file which is CSV so then for
21:07 that I have to give the exact location of the data from uh with respect to the code for so I'm saying data insert there's a file just pick that one and store in the DF variable I will run it you can run with control enter or if you just press on this cell you can also use this button to run your file let me zoom in for you more okay now here uh I want to just I just want to see the three rows of the top three rows of my data set so I have said DF do head three rows just show me the three rows that's say now you can see some statistics of your data some statistic
21:53 here not the complete but some so you can see some columns here flow duration destination ports so that's the information uh that was in the data okay some columns are missing you can't see some columns here but you can see a sample of your data okay look at that one the last one this is really important that's the target variable okay that's the target variable in the data and this is the these are the input variables and if you look at that one it says three rows you got the three rows here 0 one2 because I told them I just need three rows and 79 columns are in my
22:41 data okay it's mean that 78 columns are going to I will use them for the training the model I mean as an input and the one label one will be my as a Target variable if you have confusion in why we have uh input and Target variable this is how machine learning uh works this is the actually the classification is the problem of supervised learning so in supervised learning method we have to give a supervision of the input data so this
23:27 law this label tells that the that this line this line This is a benign one okay so this line so it's just labeling each and every record with the label so in this way we'll train the model okay so let's move forward to do some pre-processing so now if I just look at the column STS you know you can see that there's some space before that uh before that column name there is some space and what I'm going to do is that I will use the function I will say my data frame inside there are some columns okay use the function string. strip so what it
24:13 does it remove the spaces before the column names so mean you will get the normal column names without the any pre spaces that's the actually error in one data which I am removing and just running it saving it saving replacing those spaced columns with the normal columns names okay now I want to know the unique labels in my data set label which I show have shown you before this one so I want to know how many unique labels are there I can see one here but I want to know all the unique labels in my whole data set so when I run this code it says
24:59 that you have benine you have Doos label but there's as spell N N means there are some records or rows which are empty so what do I need to do I need to remove those record well you can do many things with that one you can replace that null value with average of your complete data if you if you know the True Value to label off that record you can use that information to fill up that n values null values but at this moment I
25:46 don't know anything I'm not going to replace that one I'm not going to fill up those null values so what I'm going to do is that I'm just simply going to remove those record from my whole data okay Let's uh plot that one with the help of graph so what it says let's run it it says that you have around 34 columns which doesn't have any null value but there are some around 50 columns which has the null values okay if we just go to the code so that's the PLT do figure in this figure we are defining a figure with the size of the figure inside the figure it says that I just need only one figure and I'm
26:34 defining the name of the figure size of the figure sorry which takes the shapes so the first one is the the width second one is height okay if I just reduce it by whole you can see the small figure here okay after that I'm saying the PLT PLT I'm using the library which I have imported above pt. histogram I want to show the histogram on the screen I'm saying that my data set if there is any null value is null sum them up okay and show them in the histogram after that I'm just selecting the label okay first label would be not
27:21 null the second one is null defining giving the man hiding to the graph finding X labels with the features y label with the number of features okay and PLT that shows which which shows the plot on the in the Jupiter notebook and you can see the graph here okay now we got some null values we need to remove them fine I'm going to say that I need I want to know those columns which has the null values so I'm going I'm doing here I have uh I have I've created one function which takes one parameter which is data frame okay so it says that data frame is null. sum okay so it counts all the null
28:07 value of each column fine and it stores in the missing values okay after that I'm doing the same stuff which I have done above fine and I'm plotting a bar plot here bar PLO and giving X labels y labels title main title and show okay here I am passing the parameter data frame which will go here and will get used by this function okay remember the DF is my data data the data which I have imported from the file okay if I just run it look at that one it shows these columns these column on the right side
28:53 they have the N values the column which are on the right left side the don't have any another value so I have to remove some records from the these columns okay how to remove that really simple function is there the F function is that use the data and just use the function drop and a it will remove all the N values from your file from your data from your data frame okay and I'm storing those uh all the I'm I'm storing that in data F data frame now so this data frame doesn't have any null value inside okay now uh that's the same function to show the
29:40 null values okay if I run this one it says that in number of columns so these are the number of columns 80 okay the number of n vales it says that there's there's zero null values in your 0 columns okay so that's why it's a one bar here now sometime sometime what happen is that in your data set uh n values uh can be represented with the n n string not the string I mean null uh parameter or character or it could be a imput space or but sometime it happens that it it can be represented with any different character so what I'm doing
30:25 here I'm saying that use I n f okay here I'm saying that if there is any value like INF like that PRS as a an so what they what the people do if they have some null value they also represent that null value with INF or with any special character so I'm here saying that if if I just notice in my data that there's INF is acting as a null value I will replace that work with the N so so that the python can easily handle that okay that code is doing the same stuff fine now if you move further before moving before training the model
31:10 we must understand one thing that the the model the machine learning model doesn't know about anything English word words it doesn't take English word sentences or anything as an we have to convert the data in the form of numerical values mean 0 1 2 3 4 like that so here I'm just checking the data types of my uh my data frame so is there any object data type so if there would be any object data type I have to convert that data uh in the form of numerical form object it could be object data object
31:56 data means the category data in English form like for example male female so in our case we have DS and benine two categories so so those are English word we have to convert them into the form ofical form I have checked that it says everything is false but there's one label one which has true which has the object data FM so we need to change that okay now if I come here what I'm going to do is that I'm going to convert the label in data frame to numerical value so I'm saying here in a data frame there is the column labeled Curr map map that map those categories which is benign to zero and D do to one so this map function
32:43 we'll map the minine with zero and zos with one and we'll store it in the data frame we replace that that column with those numerical values here okay so simple that's the function I going I'm again using it uh M plot one to plot the histogram of my labels giving the labels as input these are the bins bins are the bins are used to declare the spaces here okay between the the bars okay and this is the color one you can you can give the the labels to the I'm saying that B9 is equal to zero this one I'm giving label with the help of XT SC
33:29 in the math plot the I'm giving the x-axis y axis and sharing here okay so it says that in your data set the benign category are are are around equal to the D do there's not too much difference between the two these two okay they almost they are looking same fine so what that mean is that if both categories are totally equal or closely equal to each other it mean our data is balanced okay so this is really good thing if you have the balanced data set then you can use the accuracy as your evaluation Matrix so if your data
34:16 is not balanced then you cannot use the accuracy accuracy equation or accuracy Matrix for the evaluation model it is a concept here okay so they are almost equal to each other you can see the this the count of the v9 is here the D doors is here it can here is see here now uh python has one function which is described the P has one function describ it describes the complete data sets so I'm saying DF my data frame describe it so it is describing here so here you can see this is data fips I'm just using the original data frame to know how my data looks okay that gives all the explanation it says that you have how how many how many records are there
35:02 what's the mean of your record what's the standard deviation of your record what's the minimum value you can see it's a zero here and you can see 25% is 80 75% is 80 and maximum is is 61,500 normalized okay but we can't do anything regarding that the thing is that this is the network data set okay we haven't created that one we can't change it it's a network data set so we uh the the author they have captured the data within a passage of time so you will you will find the data like that the
35:49 networking you don't need to worry about that okay let's move forward and uh plot the uh histogram to know each and every feature of the of of over data frame so if I just plot that one I'm saying figure five okay I have written a loop I'm saying data frame do columns pick all the 79 columns 78 columns okay I'm taking one column but one and plotting the histogram of each and every column one by one okay I'm saying data frame pick one column plot the histogram show it then go to the next PL the second third and so on okay so if I just look at the destination one look at this
36:35 one okay you can see the zero values are more as compared to the other values in the same way you can see all the data sets uh value here so I have plot all the graph scares so these are these are all the graphs some datas are different some columns are different we can't remove them the thing is that this is the network data set we have no control on this data set okay try your best to use this data set okay this is the last one which I've seen you the zero means the benign and the do is one is that one okay now it's a numerical form 01
37:23 fine now let's move forward okay we have imported the data we have done some preprocessing on the data we have done some data analysis as uh on our data set if I go more back okay like this one data analysis feature extraction feature formatting we have converted the data in the form of numarical we have explored the data here data analysis now it's time to split the data in the 7030 or it's up to you what kind of splitting you want to do in your project but I'm going to pick the 731 so if you don't know why we split it
38:09 split the data let's let's look look let's search on the internet why we do why I'm searching on the Google so so that you know this is the actual way to to learn from the internet so I'm beside teaching you the python code I'm also teaching you how to do the self learning how to search on the Google you just search like that okay and come to the images so these images are very self-explanatory uh really the architectures are really amazing you can understand here from here like if I search your methodology TR and test yeah let's search this one now uh this is really good picture I can see that look at this point it says you have big data okay you have to split
38:55 the data into training and testing with the training data we will train the machine learning algorithm after training it will become a classifier classifier means that can classify between two categories now we will put the test data give test data to the model to evaluation the evaluation of the result or use the real world data to this model to get the result from this model okay that's why we split the data there are you can also split in the form of training test and validation as well just up to you so let's start uh let's split the
39:42 data into training and testing um you can do one thing uh if your data is really big like of like 15 GP 20 GP so you can you have to convert your data in the form of number is because the nires are much more faster 50% faster than the lists okay um so that saves the computation power you can use that one but I'm not going to I have just I was just testing it I can use that one but I don't need it I have much more computation power so what I'm going to do is that I'm just uh I'm okay with the list if you are not okay with the list uh data frame you you just convert that one into num okay and use the these uh variables in this
40:29 function here okay and then you can use that one both are same okay what I'm doing here I'm just I'm okay with the list so I'm saying here that split the data into the input and output one but before that what I'm doing here is I'm dropping the label column from my main data frame XX is one says that column so if you want to drop something as from the from the columns you have to me mention XX equal to 1 because x equal to 1 represent the columns okay zero represent the rows one represent the columns so I'm saying drop the label column from the data frame and rest of the column store the rest of the columns in my X so this is my input data
41:17 okay this is my input data now this is the uh this is the uh uh the I'm I'm just picking uh from here the label column okay label column and just store in the my the Y so this is actually my the target value Target column I can say Z okay fine so now as I told you before I have imported a function which is train test complete function you can see on the top of that one top where where I have imported the libraries so what I have done I have
42:04 used this function train test split inside that one I have given the input data input columns and output column here I I'm saying here the test size the test size would be 0.30 means I want 30% of the test data and rest of the data uh rest of the data go to the training section okay random state state defines the seed number that's okay so it gives me as an output X training data X test y the label this is the label of training data this is the label of test data okay I got the AL of the data with the help of this function X trend. shape x. shape you can see the shapes of the train and test you can see the 40
42:55 46,656 rest of them are the test RS now we have done it we have split the data now it's time to train the models okay train the models on train data and test those models on our test data I just added this one but I think it's quite big me this is just looking so weird to me let's remove that one so in this way you can create the hiding Zone in your uh uh J notebook you have to just convert it from convert into the markdown and then create the hiding scale like I just created that nice looking good okay now my first model is the random Forest so I'm I'm I'm using the SK learn
43:43 Library uh which has the function functions of almost all the machine learning model so you can import that Library I have imported on the top of this code you can import the library for that specific model just there are just only three steps just only three steps are there to train a complete machine learning model with the help of Escalon you don't need to write the hundreds or 200 lines to train a mod uh to uh train a model to evaluate it just three lines are there so before explaining you I just need to explain one slide here which I made this start of that one if I go at the end this one so so this tells that what three
44:30 lines are there okay this figure is uh for the logistic regression but the process is same for all the models okay for the first line the first line is used to initialize the the model okay here it is saying initialize the logistic regression model so in this way you just write the name of the model inside the bracket you can Define the parameters you want to um customize customize your model yeah so here I'm initializing a model the next line train the model on the training data in the next line you says the model name do fit and you fit the data you fit your model on the train and the training data here okay this is the training data
45:16 input columns and this is the top third line is used to predict the output on the test data really simple three lines to train any models so you're going to see the repetition in all three lines okay in three lines in in the main file okay there's some extra code as well if you want to do it you can do it but let me explain you now look at this one um I'm going to train the random Forest first for and the random Forest classifier okay I'm I'm initializing my model with RF model name okay what it does uh inside that I'm giving a parameter so I
46:01 I need uh 50 estimators means it's a it's a as I told you the random Forest is made of trees okay so I'm giving here the 50 trees to make a complete Forest so means estimators are 50 and that's the seed number 42 is okay after that I'm fitting the fitting my model on the train data which is extra and y train we which we got above here x train y train so here it trains the model okay it will take time here data is quite big it will take time here okay after training the model you will get the train model here here and it will
46:49 provide you a function do predict which will take the X data and will predict the the the output of X data okay now we got the train model and we we have given the test data and we got some predictions here these are some predictions of the model all of predicts okay must remember this variable now out of Model provides many many functions I am what I'm going to do is get I'm I'm going to use a function features importance to know that what features what columns are important for my model to predict the good output so these are the code which takes all the columns features names this is a simple
47:34 Loop that's the mat plot lip which I have explained you many times it just Define the size inside that when you're giving the column names okay range importance importance you got here with that function here you're giving here inside that you giving the indes names okay y t is the same to give the name to those categories X labels are there title is there show is there okay after that you will see a graph okay what it says that these are the features these are the columns okay these are really important for your render Forest algorithm 66 is really important 68 is really important okay in this way it's
48:22 declining okay here till here what you can do is that you have trained the model you got the importance what you can do you can delete this coln because you don't need these are not important for your model to predict the proper output okay you can delete them as well now let's move forward to you know here I have given the 50 estimators this one you can plot them how they how the how the random Forest made the decisions on your on your data sets Okay so these are the 50 uh estimators a complete tree there you can zoom in to see what's happening inside that one this is this
49:09 is actually decision in each note it makes a decisions to move on the left or right okay till here now we have train the model we have test the model then now it's time to evaluate the model on the testing confusion Matrix is really important thing for in evaluating the model if you if you have no idea about that one kindly search any YouTube video blog to know about that one then come here okay we going we are going to use the what what we are going to use here okay we will calculate the accuracy a score recall prision confir let's
49:54 go so because I'm going to create the three confusion Matrix for three different models so instead of writing code again and again I have created one function of can Matrix and I'm going to use that function again and again fine I'm saying this is my function name okay pass the Y true attributes means the Y Target of the of the test data the values which are predicted by the models class is name title title of the uh model is it random forest or is a logistic regression or what this one
50:40 okay inside that one that's really simple I'm using a confus matric function giving the input data which I explain you there rest of the code is say just I'm here just plotting the heat map with the cbone library okay you can read about these parameters and you can add modify them these are just defining colors shape size and classes and everything title is for main title X label y label and the shows both are same okay that's the function I have created it here I'm using accuracy functions to give the labels of Y test and the the prediction done by the model okay you give as two things input and it gives you the accuracy I'm storing in this one
51:25 in the same way I'm calculating F1 score precision and recall and with the help of print statements I'm plotting this all everything here look at that one I the 0.9 accuracy of this model or the test data unseen data F1 score is there which is which is really good prec is there which is perfect recall is there which is also really good okay now let's let's use the function of confus Matrix to draw The confus Matrix so here I'm say giving the labels of Y test prediction done by the model and classes these are two classes remember that all classes were in the numerical form 01
52:10 okay so that will convert those classes back into the names now that's not going to convert that's I'm going to use those classes as a here xais sorry for that here like that okay so and then title me render Forest conf Matrix one okay if I just zoom out that's the confused Matrix of uh my Ren Forest that's the true positive that's the true negative means model is perfect perfectly identify the true labels uh the the the attacks attacks
52:56 okay attacks are here non attacks it has unique perfectly identifi that one but there's some results this is 10 so my model predicted 10 result as a false so that's why this is accur is little bit low okay fine now let's move to the next model which is logistic regression simple which I have defined you in this slide this is this this is by the way slides of the logistic regression you you just need to define the model give the data to fit on on the data and then get the prediction really simple really simple I have done that stuff here and this is my LR model logistic regression and storing the
53:41 prediction on the test dat on the allot predictions okay if I come down the same code for the accuracy F1 score and everything it gives me the accuracy here so it has little bit low accuracy as compared to the render Forest F1 score is still low pan and recall okay I'm using the same functions to plot my The conf Matrix and you can see look at that one uh perfectly identified D do attacks not identify sorry for that it means perfect classified okay classify because this a classification problem it's a classify between two things okay so it has perfectly classified do pack b n perfectly 8,000 okay but there are
54:27 some some entries some records it it it has some error to to classify those entries so these are 73 here 94 just go and understand the config Matrix then you will know what these two things are these are actually false positive and false negative things but I'm not going to explain you here you have to learn it by yourself okay now let's move to the um machine uh I mean I mean not new Network okay MLP means the multi- layer per subron classified okay it takes the hidden layer hidden layer size that is 10 so there there's some some hidden layers which has neurons the size of 10
55:13 so middle line is 10 let's let's read it what what what that means so you if you don't understand anything you just come on the Google and you can learn from the pictures okay look at that one this NE Network so what I'm saying here okay we have the inputs that's fine no issue this is the hidden layer so I'm saying I just need one layer with these 10 neurons 1 2 3 4 10 minus 10 okay after that just give me the output I just defined one lay but you can customize this model you can put the five layers 10 layers 20 layers you can make this model more complex okay you can test it train it again change the lay layers is up to you you can do a lot of experiments but what I'm doing this
55:59 thing at this moment just only one hidden layer is there okay it's by the way similar to the brain neurons but the small okay the same stuff tions means the Pok Run 10 times on my data okay fit on the data test on the data and after that I'm I'm using all those equation again and measuring the accuracy F1 score prec and recall and look at that one it got the 98% accuracy F and score same recall and prec more better than the logistic regression okay now again I'm drawing the confusion Matrix and you can see the conf Matrix of that one here now the the we have trending random Forest logistic regression and the new
56:44 networks okay now the question is question is to to compare three models of course you can compare here with the help of three things accuracy f one score and prec and recall you can easily compare which one is better and which is not okay but for example if you're training 20 models 30 models 40 models okay at that moment you cannot compare with just just just remembering the accuracy ofion model and compare that okay which which one was better and also it it it was a lot of other parameters you have to consider the Precision recall in your mind to compare all those models okay still we can compare the accuracy of three models but we have to keep in mind PN as well
57:32 okay recall as well so there's one concept which is the ROC curve that concept is used to to check which model is is which which whose perform whose model performance is really good okay means it is used to compare the machine learning models Concept in simple way so what I'm going to do here is I'm as you remember on the top the this was the rendom forest model Trend one this is the logistic regression Trend one this is the newal network Trend one what I'm doing here I'm just using the function predict proba so on the top uh if you look at there I have used
58:18 the function. predict and given my data inside so when you use the function predict it gives you the uh answer in the form of 0 and one means it gives you the 0 and one but here you get the probabilities of both of them probabilities of means that if I here it says that predict that probity will return you that what's the probability of zero or one in the output of any model so what we do we we will store those probabilities and we will pick the maximum probability okay what I'm doing here I'm saying that okay pick the maximum probability either might be zero
59:04 I mean Bine has 2% probability and then dor attack has 8% so we we are picking the 8% the maximum one from here giving the true labels and this function we are calculating the a the RF false positive rate and true positive rate which is uh actually which helps us us to calculate the Au area under Cur yeah so these are two parametrics you can calculate from The confus Matrix so false positive rate true positive rate okay we also call them recall and precisions which I have calculated above to calculate the Au I'm G I'm giving you as an input there okay in the same of for three models
59:50 now that's the main thing let's move let's look at the image first so as I told you Au Au means area under car see the more area uh the more area is under the curve means the more better the algorithm is okay look at that one render Forest has complete data under the curve means it's best one all of them logistic have 0 0 Z right okay this is the curve you can you can learn this code that's self explanatory by yourself thank you