 First basic example, I will give you 2-3 examples, so that you can understand end to end application of logistic regression. The theoretical understanding, the technical understanding we have covered now. Now let us see couple of applications. Here you can see consider a data sets where we have to classify whether the person own a house or not based on his income or her income, right. So here we have put the data. So this is the income of the candidate based on her income, whether the candidate or the person is owning a home or not that shows the data based on the survey. So you have the data now, but look at the outcome data are in a binary format. The question is that what is the logistic regression, how we will implement this model or what we are going to build, what is the question here then. The question here is that this is the income of the person, only one independent variable we have considered, one predictor variable and this is the say predicted variable or say you can say the outcome variable. These outcome variables are not been you know what is the cost of the home etc, this y, what is the cost of the home we are not discussing, we are calculating the probability whether it is a 0 or 1 like yes or no, so probability will convert into the binary outcome yes or no. So now here this is the you know sample data will fit a logistic regression line P by 1 minus P equals to say beta 0 plus beta 1 A x and then we know the formula P equals to 1 by 1 plus e to the power minus a beta 0 plus beta 1 x using this either of this formula we will be able to calculate for a new candidate, for a new candidate with say income of say 3 0 0 0 suppose right, if a new candidate come, if a new candidate come with this much of income whether the persons will have the own, will have the own home or not that you can get from this predicted model of logistic regression. How we will get it? Look at the from this data from this existing data sample data, you can fit the logistic regression model with we are understand by calculating the coefficients, you can fit the model look at the logistic function we have draw the symbol function and the probability are been listed in the left vertical axis now, now for a new candidate 3000 say right, 30,000 say. So, 30,000 will fall suppose somewhere here. So, generally 30,000 is falling here, generally the data set says that the persons may not have own the own home, but if it is say 70,000 say 70,000 probability you can see it is coming here. So, probably it is the cutoff point if your cutoff point say look cutoff value is a 0.5 say, 0.5 say cutoff point in that case you can say that you know 70,000 income in that case the persons chance are like here. So, probability that persons will have his own home. So, this way you apply the logistic regression after defining the formula the relationship with your data sets and the probability of occurrence. Look at it is a probability of occurrence this is it can a range of it will have a range of 0 to 1, 0 to 1, but since we have put a cutoff point based on your understanding or decision making process where to cut you are classifying the outcome into two category yes or no and for a new candidate whether it is 30,000 income or say 70,000 income you will be able to predict whether the persons will have his own home or not. Basic example I have given now let us understand with a larger application. Now, we have taken a another interesting application suppose the relationship between the age and the sign of heart disease we are under we would like to calculate right through logistic regression how the model will work here let us understand. Here you can see the age sample sample you have to collect first here you need some more sample than regression analysis right more sample will give you a better prediction of logistic regression, but in linear regression if you have a very less sample say less than 20, 25 in 10, 12 also you can use the model of simple regression, but in logistic regression if you want to come up with accurate predictions you need around 50, 60 or maybe 1000s of data then only you will be able to make a better prediction. Some sort of higher data are required to make a actual prediction because your classifications will be done into binary kind of right cases right. So, here you can see suppose age are independent variable only age we have considered and these are the sample and the heart disease cases are been listed here from a report say. So, here you can see age 22 there is no heart disease say 0 suppose here we are considering no heart disease here 1, 35 age 1 cases we found, but when the age are increasing look at age are getting older person look at the heart disease cases are increasing. So, now for a new candidate for a new person we say age say 55 say right or say you know say you know say 30 say 45 whatever you can condition what could be the chances of heart disease. We will calculate the probability first the chance will calculate the chance will calculate chance will calculate the probability will calculate first after that we will convert based on the cutoff point into 2 cases, but based on this data we found the no disease cases the average no disease cases are 38 years of age and the disease cases the average based on the data all 1 we have put together and we have taken their average if on average age of 58.7 years people will have a heart disease, but on an average based on the data sample 38 years of age of people does not have the heart disease look at the sample look at the sample. So, we have the basic you know like you know descriptive analytics with with their hand now I have to fit a model first and then you have to see the pattern of the data and then you can for a new person you can predict. Now, look at this data this data are being classified into this way right cases of disease and no disease no heart disease say and you cannot fit the regression line right because it does not have a ceiling. So, you have to cut. So, you put the logistic symbolite function and then sigmoite function sigmoite function right and then you put your p equals to 1 by 1 plus e to the power minus of beta 0 plus beta 1 h right you put this and then you fit your model here we have done it look at this. So, first what we have done we have classified the data into groups. So, here 20 to 29 years we found 5 sample and then 30 to 39 6 sample and then 40 to 49 7 sample we have calculated couple of sample 1 2 3 4 5 6 and here how many cases of heart disease we found between the age group of 20 to 29 nil nil no no one 30 to 31 only 1 cases 30 to 39 only 1 cases here you can see 30 to 39 here 35 1 candidate with age of 35 has a heart disease it is exceptional case. So, but we found that 1 and then 40 to 49 2 cases, but 7 sample were there. So, for 80 to 89 we found 1 cases 7 to to 79 2 cases. So, we found the data frequency and from that we have calculated the probability value in terms of percentage which will be here for us to understand. Look at here with the age of 80 to 89 only 1 candidate are there, but the candidate has a heart disease. So, 100 percent outcome are coming out to be these even 7 to to 79 2 candidates based on this existing sample if you increase sample size your prediction formula might change little, but suppose 7 to to 79 case group 2 candidates we found both the heart disease. So, it is your 100 percent chances that they will have a heart disease, but when the ages are reducing 60 to 69 age category 5 people only 4 has the quite high has the you know heart disease. So, 80 percent people are like 4 by 4 by 5 almost 80 percent people are coming out to be heart disease having heart disease, but once the ages reduces you can see the percentage of heart disease are been reducing. So, this plot this data we are going to plot here say in our different example I am showing we are going to plot in our graph. So, age group are here in different category category 1, 2, 3, 4, 5, 6, 7, 8 say 7 and look at category say 7 and say 6 and 7 these 2 category 6 and 7 last 2 category 6 and 7 both are 100 percent chance of heart disease look at 100 percent both have the 100 percent chance of heart disease. Then it is reducing, but look at the age group of like first age group of 20 to 29 no chance of heart disease 0 percentage of heart disease. Now, similarly you can see this now for other you have plotted, but look at the pattern of the graph what type of pattern it is following is it a straight line no is it a straight line is it a straight line no it is not a straight line rather because there is a selling look at after that there will be 100 percent only like and there is a no case below age 20 there will there might not be any cases of very rare cases of heart disease none of them will have heart disease. So, you have to put a right graph like this right. So, therefore, we are putting the same word function for this formula. So, this formula and that is been replaced with this logistics function to balance the range of the data sets 0 to minus infinity to infinity and this also says the minus infinity, but we have replaced that replace this data this data with this graph through this symbol function. Now, since you have replaced that with a symbol function with your own data sets. So, this will come as a probability now the selling is 0 to 1 0 to 1 0 to 1 and your probability are here now corresponding probability are there now for a new candidate for a new candidate for a new patient whatever the age you do have like this is a bank or say you know insurance company or the you know people who use the logistic regression they apply for a new candidate based on this pattern of the data sample size they have fit the model now the formula are being done pattern coefficients are being estimated. So, probability formula are done logistic regression model are we also do with your understanding. So, now you put a new candidate come back where the age is falling. So, you can calculate the chance of these candidates whether we will have the person will have a disease or not if it is falling above your cutoff point say 0.5 0.5 above your cutoff point you say the persons will have disease, but if you found a new candidate whose cases are coming probability here say we can say that their candidate might have a disease but you are predicting right this is a prediction you can conclude that the persons will not have a disease because your cutoff point are here. So, this is what the application logistic regression now if you extend this concept to more than one variable independent variable suppose here we have put three independent variable you can add more also in that case we call it as a multiple logistic regression because more than one it is not multinomial your category is only 2 0 or 1 binary outcome will be there of your output value not the why we are going to actually calculate we are going to calculate the probability of success or say failure remember here also we are not calculating the y value right we are calculating the whether the persons will have a heart disease or not yes or no that data we do have and we are predicting it right whether to approve the loan or not insurance claim is a fraud claim or right claim that yes no kind of outcome we are going to decide after that how much amount you would like to disbarse etc that is different case. So, now we are taking the initial call through logistic regression. So, therefore, in case you have a multiple logistic regression or more than one independent variable how does it work the formula will remain same as it is everything will be the same your p value will be you know 1 by 1 plus e to the power minus beta 0 plus beta 1 x 1 plus beta 2 x 2 same formula plus dot dot dot same formula and the corresponding logistics function formula for your understanding with range understanding will remain the same. Let us understand in that case look at increase in order logouts in one unit increases in x 1 say or x i with the other keeping constant your interpretation of the coefficients the correlation and the coefficient linear relationship are being developed the same logic how much changes are happening in your output cost like logouts if you change one unit in your x like the way you do regression right y equals to alpha plus beta x what is beta if you change one unit in x what is the change in y right say it is a slope. So, this the rate of change are been defined here also then if you change one unit keeping all other constant if you change one unit even in multiple regression you can do like this right same logic we have done it in regression analysis multiple regression here also same logic, but here you have more than one independent variable or predictor variable where your outcome will be only on binary like through probability and then you convert into two cases of binary. So, this logistic regression of multiple cases will remain same just a basic understanding extension of basic understanding. Now, let us see one interesting example this example of more than one independent variable will not only be illustrated this will be used for confusion matrix analysis also in practice in real life application or in industry people not only take the decision that whether to approve loan or not people calculate the accuracy level of your model whatever the logistic regression model we have used it is common for everybody right for you know at least binary cases you can fit the model, but the point here is that what is the accuracy level of your model that also is very important right you can predict, but it may come up with the wrong prediction also we can say ultimately it is a prediction model so they are also forecasting. So, therefore you need to calculate the confusion matrix in logistic regression the accuracy level the accuracy level of your model has to be calculated this has been calculated through this confusion matrix. So, there are four categories one is the two positive this is the actual case of data say I will show you in a through a example, but first understand the basic concept of confusion matrix you have a actual case of data and you have a predicted model for your logistic graph right logistic model you have p value you know p equals to 1 by 1 plus e to the power minus say you know what about the formula right beta 0 plus beta 1 x plus dot dot you are adding more variable here suppose, but for even single variable also you can make the predictor this confusion matrix. So, now in that case what happens this is your predicted model and this is your actual data. Now look at the true positive case what is the concept if actual is positive and your model also predict positive in that case the outcome decision final decision is a true positive, actual is also positive look at the blue color actual is positive your prediction is also positive, but actual is positive the person has the heart disease or person may you know repay the loan, but your prediction says that no no no no person does not have heart disease or person cannot pay the loan because prediction model can come up with wrong outcome right exceptional cases we have seen, but general structure says that if the actual is positive, but your outcome is negative then we call it is a false negative false negative because actually true false negative similarly if the actual data are negative and your model also say negative then you call it a true negative look at the matrix, but if actual is negative, but you say positive person is died, but you are saying it is a you know survived right. So, in that case negative we call it is a false positive because you are saying false positive, but effectively negative. So, these are the confusion matrix and these are the four parameter of calculation accuracy level is nothing, but true positive true negative by all possible outcomes this is the accuracy level this is the most important part there are few more aspects like sensitivity specificity and the precision sensitivity is nothing, but the true positive by true positive and false negative look at this is this two case. So, true positive true positive by true positive plus false negative this is nothing, but the sensitivity look at that sensitivity measure the proportion that true positive predicts out of the actual positive instances right. So, it indicates the model stability to capture all positive indices similarly specificity measures the proportion the true negative out of the all negatives this is what the specificity look at true negative by true negative and true false positive. So, these two cases are there and one other is a precision precision are nothing, but you can say the measure the proportion of true positive prediction out of all positive predictions only all the positive prediction look at it is a true positive and false positive based on that what is the case of ratio you are getting that we call as a precision, but all these four points or you know calculations are been important in different cases examples in the discussion process you can come up in this case what could be the outcome what could be the probability what could be the chance ratio value relative value all this you can understand and you get a better insights about the model, but effectively the most important part is the accuracy level of your model like you know true positive and true negative both are good cases right your model is giving a good predictions based on the total predictions that you have done you found from your model. So, that is called the confusion matrix let us apply it. So, here we have taken a data sets we have taken this data from Kaggle the titanic data sets there might be more like more than 2000 people where they are most of like only 800 people or couple of people have survived we are not talking that we are talking the example or application of logistic regression here. Here we have taken a data sample say 891 sample sample couple of sample we have taken and this is a passenger ID say passenger ID and this is the data that we do have in our secondary data sets one means diet and zero means not diet that means survive. So, one we are we are trying to predict whether person has died or not from our logistic regression understand look at dependent variable are these died or not if died then one if died or then one if not died then it is zero you can change the data survive or non-survive also many people elasted this model by using the word survived or non-survived here we have used diet or not died or survived. So, this way diet is our one right if the person died. So, the death will be represented by the one value as a dependent variable and independent variables are been given here what are that passenger class like class one class two class three in titanic you know all know there are many type of class of passengers where they are right and the sex of the candidate whether female male that has been mentioned here and the age category of the candidates and the fair like if there is a high class then there will be high fair also in terms of dollar suppose data are been given. So, how many independent variable are there four independent variable right or predictor variables are here only one dependent variable one one dependent variable that is what the person has died or survived or not died. Now, these are the data set now we will use the logistic regression and for a new candidate we will see what is the prediction whether the person has died or not from our model and what is the accuracy level of our prediction model right that is the most important part of the industry required. Now, using excel stat or Adrix software or you know Python you can run the model you take the data you take the data and put it in your software run the logistic regression model will give you the results I will show you that also but for the time being let us understand the outcome of your model just put the data in the model you get the outcome. So, here first we have done the basic regression using the maximum likelihood function or say you know the software that you have just put the data you use the logistic regression and drag it like in regression you do you will get the outcome right. So, here we have four independent variable predictor variables and one constants intercept you can say and we found using our logistic regression model we found the p value for all of them you have to see whether they are significant or not right we found fair value the p value of fair independent value is very high 0.87 rest all are you know significant you can see less than 0.05 but for fair it is 0.87. So, you can include fair right it is not explaining your decision of whether the person has died or not maybe fair and passenger class are correlated fair and passenger class may be correlated therefore, you need to exclude it but we in your dataset we found fair has no relationship with your decision variables. So, because it has a high p. So, you exclude the fair. So, therefore, you cannot take these coefficients into your model beta 0 like you know ln of p by 1 minus p equals to say beta 0 plus beta 1 of say p passenger class plus beta 2 of say sex plus beta 3 of say age plus beta 4 of say fair you cannot take this right because fair is not coming. So, you cannot take these coefficients you have to remove fair from your datasets and you have to rerun your logistic regression by considering only three independent variable or predictor variable passenger class sex and age because they have the significant relationship. Now, you rerun your model and then you see what is your final prediction of your logistic regression model. You rerun the model simply put the select the data exclude the column of fair and rerun the model right consider three of them these three of them as your independent variable and diet as your dependent variable binary kind of outcome. Now, you feed the model logistic regression model and you get your outcome. So, here we found all all of them has the significant. So, we will select the model look at our final model now look at passenger class sex and age. Using the logistic regression outcome or maximum likelihood function or the software you will get the coefficient also beta 0, beta 1, beta 2, beta 3. Your model is set now either these or you know you can calculate the p in the next slide also you can calculate the p value also p probability not this p, p is the significant of your statistical set from the analysis. This p we are not considering here we are considering the probability of your logistic model through which you can calculate the really relationship of your logistic regression also, but that we will not consider we will consider this function to calculate the probability. So, now come here look at here. So, p we found 1 by 1 plus 1 by 1 plus e to the power of this formula right. We found our probability and the logistic regression function model the relationship of your model done now formula is ready now. Now, for a new candidate you know the class new candidate new passenger right new candidate or passenger you can also you know in the titanic example you can see the passenger class you can calculate the sex you can give the input of age sex and passenger you will get the probability of the passenger, but where it is falling upper side or lower side 0.5 year cutoff point say then you can say that person is died or survived or not died. Remember in our example we have considered one means died right. So, we will understand our problem or illustrate our problem accordingly one means died right. We want to see how many people have died that we want to predict. Now, here you can see and we will use everything the accuracy level through our confusion matrix first understand the logistic regression outcome. So, look at the final data sets. So, passenger class died, passenger class a passenger ID, passenger sex age and fair fair we are not considering. So, we will exclude this right and then we have found the probability we have found the probability say function the logistic regression formula using symbol function and the coefficient also we calculated. Now, look at the previous case all this case is the data we will calculate the prediction from our model the actual died case we already have the second column this is our actual case right actual case data. This is our predicted case. So, for one you put one here like you know candidate one and you can see the data with first ID ID case first ID you will find the age the corresponding you know sex and say male female whatever and the age you put and the passenger class you will find the probability 0.10. So, probability 0.10 means what you put here this is your predicted probability. Now, for any candidate say candidate number 7 candidate ID 7. So, what would be the predicted probability predicted probability for candidate 7 a passenger class 7 say candidate 7 say would be 1 by you know 1 plus this e to the power what whatever the values you will put what values you will put these values 1 0 and 54 you put here 1 0 and 54 you will find the corresponding probability what would be the probability 0.29 look at this 0.29. So, all this prediction we have done now, but these are the actual probability value from the graph right from the graph from the same void graph we found the corresponding probability for any candidate passenger ID we found the probability value here corresponding and we have listed here. Now, you have to classify them. So, look at here we have put the 0.5 azure cutoff point 0.5 azure cutoff point right cutoff probability. So, first candidate is 10 percent. So, it is a below 0.5. So, you are considering death means higher 1 right. So, here 0.10 so, means a person is actually survived. So, it is 0 1 means death in our example first case it is 0 second passenger ID we found 0.91. So, it is death that means it is 91 percent. So, it means that our probability are saying 91 percent that means the person is died. Therefore, it is 1 because in our case we have considered died as the outcome as 1 we are representing that. So, now third candidate 0.571 0.94 candidate 1. So, next fifth candidate 0.6 percent only. So, it is survived it is not died 6th candidate 7th candidate not died. So, last look at last candidate of our sample it is not died second last it is died. So, this is the classification based on this probability of the prediction of our model now. Now, you have two data sets one this column and another this one this one the actual the actual survived or death case and predicted death predicted death or say survived case. One means death in our model 0 means not death that means not died that means survived. So, now go to the confusion matrix. So, we have taken these two column now look at first candidate survived not died our model also said not died. Second model died our model also said died third case third candidate died our model also predicted died fourth case you might say the all matched model is good almost look at this 80 percent accuracy other 79 percent there are couple of issues where you will find that it is not matching in between there I will show you in excel you will get to know there are couple of cases which will not which will not match our prediction will be different than the actual cases. Here you found the final results you can see the confusion matrix true positive look at true positive the actual is died our model also said died here you might say the all matched but it is a couple of sample I have put when I will show you excel you will get that variation. So, actual is died our model also said died only 240 cases are coming and actual is died but our model said not died 100 times we have predicted wrongly look at actual is not died our model also said not died 467 sample out of 891 are being predicted accurately. So, actual is not died survived our model also said survived actual is not died or survived our model say no died 82 candidates are coming. So, this is what your confusion matrix right and corresponding sensitivity specificity and precision you can calculate the actual value accuracy value also you can calculate look at true positive and true negative by all outcome you will get 79 percent accuracy of your model. So, we have come to our normal screen of excel we illustrate this problem of titanic with logistic regression example in excel now. So, you can see the data these are all data. So, we have passenger ID column then died passenger class sex age and fair. So, we are considering this 4 variable class to passenger class to fair as independent variable and then we are considering died column number b as our you know dependent variable. So, this will be you know binary kind of thing died and survived. So, we are considering died mean 1 means died 0 means survived. So, this we are assuming in our analysis. So, you can think this way many people consider you know 1 means survived 0 means died. Here we are trying to see how many people have died right throughout our example. So, we will consider 1 means died. So, what you have to do you just run the logistic regression here you can see we have installed the excel stat it is a excel additional feature which you can download through poly shade decision tool suite which I will illustrate detail in simulation session. But here I will show you the application of that software it is excel adding like excel different like you have another software called excel stat real stat you can install them also or you can run this different type of analytical software like logistic regression Arrimion etcetera and different type of different additional multivariate data analysis you can do here we illustrate only the logistic regression part. So, here you can see this is the general excel home but here we have added the additional excel tool like stat tool of address analysis. So, come to just import the data first data set manager click this go to new and then select the data sets. So, we are selecting from say you know this we can select all actually and then all data we let select and then here click ok. So, data been imported now come here look at the logistic regression time series also analysis you can do all this, but we have done all this illustration in excel basic excel, but you can use the software also. So, here since it is advanced logistic regression is advanced ML process. So, you need some you know direct excel it will be difficult because you have to do entire analysis of maximum likelihood and all these things here in a readymade software you can understand that easily. So, select dependent variable diet as a dependent variable and come to independent variable case passenger class select them sex age and your fare right. So, all of them we are considering independent for the timing all four and diet we have considered dependent variable look at D select ok click ok your results will come. Here you can see we have found the result through excel state of logistic regression and all this analysis you can see, but the problem here is that here you can see the p value of fare is quite high 0.87. So, therefore, it is not significant it is insignificant it is not explaining the dependent variable that is the diet or survive effectively. So, we will exclude it from our analysis and then we will rerun our logistic regression model again. So, let us exclude it and then we will rerun the model because it is the p is very high it is not significant it should be less than 0.05, but for all other it is fine, but for fare it is not less than 0.05 it is quite high. So, you have to exclude it the diet is not dependent on fare. So, it is a no relevance. So, go to here you can see logistic regression again. So, here what we will do we will exclude fare from our data sets from the independent variable set. So, we are considering passenger class sex and age and now we are running the rerunning the logistic regression model again and we found the result by excluding the fare here you can see fare is not coming here. And now all of the independent variable look at here all of them are significant all of them are significant. So, we can say that you know all three passenger class sex and age has a direct impact to your dependent outcome dichotomous outcome of decision variable that is called diet whether the person will die or survive. So, now this is the outcome of the results and you can see the accuracy level confusion matrix 240 which I have explained in PPT 240 100 and this 82 and 487 and the results all these results you will find here we have kept in another seed. So, here you can see that was the raw file and we have done the predictions and we have calculated the probability like I have shown you in PPT. So, we have calculated the probability like here you can see the probability part like and the corresponding the probability part we have calculated here and based on that based on the logistic graph we found the first candidate is coming out to be 10 percent right first passenger. So, 10 percent means point cutoff point is 0.5 which is below. So, it is we are putting the final decision as binary as not death it is a survive like not death because that is death one means we are considering death. Now, second passengers it is coming out to be as per our final outcome from this formula we are finding the second candidate to be 0.91. So, you can see 0.91. So, 0.91 is quite high above 0.5. So, we are considering that candidate under death category. So, this way we have done all these analysis and the corresponding probability conversion binary conversion 0.1 from this probability outcome we have listed here. Now, we will segregate them and we have created the confusion matrix here you can see death this is our prediction and this is the actual column B is actual and column C is the prediction and we can see the matching now actual death and our prediction from here we are we are getting 240 cases and actually died, but we are saying no it is a not died. So, the wrong prediction is coming out to be too negative or coming out to be 100. So, this way we have calculated the actual survived and also survived 467 cases are matching. So, this way we have done the confusion matrix and if you see the final outcome of both cases here you can see here with fair cases we found that 0.87 just I have shown you, but if you exclude it and this is your final outcome results you can see all three are there passenger class X and age and the corresponding in a confusion value and the accuracy level you can see 79% and all the results are been also replicated here. So, this is what the effect of logistic regression using the excel illustration also. I believe it is clear to everybody how the logistic regression work and how the model are been developed and where to apply and how to read the logistic regression model and how to calculate the accuracy of a logistic regression outcome through confusion matrix. With that let us conclude the session of logistic regression remember there are many extension of logistic regression are there. So, far we have discussed only the binary case and two cases simple and multiple independent variable, but we can extend that to multinomial logistic regression where you know your category could be student, teacher, farmer different type of outcome will be defined like this way not only the binary cases you can consider the ordinal logistic regression where the rank will be defined like low, medium, high kind of thing. The different type of application of logistic regression are there, but we have restricted our discussion in this session into the basic binary logistic regression with two simple cases one is a single independent variable and more than one independent variable that is a multiple independent problem. And how this you know success failure or the yes no or decision of survive or die cat it could be measured and may be predicted for logistic regression that we have discussed through this session. Thank you.