Hello all welcome back to design spren in this video we will be doing another fun project where we will be making an end to end machine learning application for stock prediction so this is how our application will be working so we'll be selecting these options like gender male and then we'll be entering the age we'll say hypertension we have hypertension we have heart disease and our work type is let's say Self-employed and marital status is as resonance type Urban glucose level let us say it's around 500 BMI let's say it's around um 60 and smoking
status smokes and once we click predict stroke see it has predicted that that you know we'll be having a chance to get stroke okay so predicted stroke one means there's a chance to get stroke so similarly let us enter the uh lower values like gender is female female you Have less chance of getting stroke age 20 heart disease no hypertension no ever married no uh work type never what glucose level let's say 80 resonance type Rural and BMI let's say 30 smokes never smoked and as you can see it has predicted stroke to be zero
that means uh this guy doesn't have a chance to get stroke so that's what we will be building a web application for stroke prediction okay okay so uh first of all We will be actually doing an uh explorator data analysis on the stroke data set so we will be actually uh making this project based on this uh data set like stroke prediction kaggle so there's this data set uh for strock prediction from kaggle so this is the data set that we'll be using and uh so first of all we'll be doing some exploratory data analysis
and after that uh we'll be proceeding with this application okay so let's get Started with the code kindly leave a like and you know kindly comment your suggestions uh in the comment box and also subscribe to my YouTube channel if you haven't already okay so I have made numerous uh tutorials and projects like this you can check it out uh in the playlist so kindly leave a like share this video with your friends and you know leave a comment okay let's start by importing the data set okay so as we have done in Uh all
our previous projects we will be mounting the Google Drive okay so let's click on Mount Drive so this will basically allow us to import the data set uh after uploading it to Google Drive okay so I have already uploaded mine uh so I'll be mounting the Google Drive now and I will and you know I will just copy the path here and I will keep it okay so as usual we will use pandas so I about pandas as speeding not DP PD shift enter and it will run the code And we will store it into
a data frame okay so let's say DF is equal to PD do read CSV we will use the read CSV function uh from pandas to read the um data set so I'll paste the path that I have just copied so this will load the data set and uh let's just take a quick look at the data set let's say head shift enter and we can see the DAT set here and also we can see that you know this this ID column here which is not really useful for us so we can just Drop that so
we will say DF is equal to DF dot drop and we will say we need to drop ID from which axis from the from the first axis okay so it will drop the column uh okay I typed in prop okay so it will drop ID from The Columns okay and we will again say uh not there we will justy and paste here so we'll do the drop and then we will just look at the data set okay so as you can see these Are the columns we have so these are all the feature columns and
this is the uh this is our uh this is the column that we are trying to predict okay so stroke stroke is our Target column okay so we we will just print it uh like this okay we don't have to use head so we can see both head and tail here so we can see stroke has um like binary values 1 and Zer and uh let us take a look at other features gender age hypertension heart disease ever married work type residence Type glucose level BMI and smoking status so these are all of Futures uh
these feutures will decide this target okay so gender male or Fe email uh so we'll we'll be further looking at all of these features individually and seeing how these will affect the our Target variable so just a quick look gender uh male and female age uh is there hypertension is also looking like binary value Heart disas is also binary value ever married is also a categorical Variable it will be uh it will be having two values um gender is also categorical and work type is also I believe having uh categorical uh values like few of
the repeated values the sance type is also same glucose level is a numerical value continuous numerical value BMI is also a continuous numerical value and smoking status is again a categorical variable okay so that's a quick look and gender means obviously male female age is the age of the patient I mean age of the Person hypertension uh says that you know whether or not the person has hypertension or not one means it he has it zero means he doesn't have it heart disease is also same one means uh the P the patient has heart disease
zero means he doesn't have ever married also has Yes or No Yes means he's married uh no means he isn't married okay uh and also I think uh it is better to you know uh write some code to see the different uh columns here and it's uh different Values I think so let us look at the unique values in all the C categorical features so we will say we will say categorical features categorical categorical features is equal to let's make a list of it list of all the names we just copy it like this and
gender is one AG is not hypertension and now we will get the unique values Okay so say unique values is equal to we'll say for call in uh categorical variables categorical feutures um we will say we will map call to the unique values okay the unique values in that particular column okay so this will give us a object containing the column name with its unique values as an array okay so we will just do this and we will print that Out uh in this way it is not that easy to read so let us make
it little little bit more readable so we'll say call values in unique values do items now this is really useful in Google collab Okay so we have this future where you know we'll get suggestions to what all code that you know we'll be probably going to write okay so as you can see gender has male Female and other hypertension as we have discussed has zero and one one meaning it has hypertension zero meaning no hypertension her is also similar one means has zero means doesn't have ever married yes or no uh work type private self-employed
government job children children here means you know uh the patient or whoever the uh data set isct from is a child okay so children never never work okay residence type urban and rural two residence types smoking status Formerly smoked never smoked smokes and unknown okay stroke our Target variable has only two values so so the uh problem at hand is a binary classification okay so binary classification is the task uh so I mean you can say it's a classification or a prediction so we we are basically predicting stroke right so we can say it's a
prediction okay so that's a thing so basically in machine learning terms this is a classification isn't it so this is a Binary classification machine learning problem but you know when we are like you know communicating this with someone so we'll be saying like this is a our model is a stroke prediction model okay our our application is a stroke prediction application so understand the difference okay so this is a classification problem in terms of machine learning machine learning perspective but you know in like in a uh like when we are trying to Communicate this to
someone else or general audience we will say our application is a strock prediction application okay so it's a it's an interchangeable uh thing so now we will further uh explore the data set so we will we will check for some uh any duplicated rows here so we'll say duplicated do sum so this will return as the sum of all the duplicator rows and we can see there are no duplicator rows here uh don't have any duplicated rows And now let us uh just see some information about the DAT set okay so we will use the
uh common info function uh to see some of the information about the data set so we can see there are 5,110 entries that means there are 5,110 rows here and um we can see most of the columns are uh having uh complete values uh there are no null values but BMI BMI column only has 4, 99 non null values that means that there are some null values in present in BMI column as we Can also see here we can see Na and here so we have null values in BMI column and we need to handle
this okay and as I have mentioned before we have many uh categorical variables here and which we need to deal with because machine learning models generally tend to work well with numerical values okay so we can we have to convert the categorical variables to numerical variables later on okay and also we need to deal with the null value So that's the uh that's what we have from a quick look and so our problem is binary classification problem and uh at present we need to deal with two things null values and uh categorical variables so let
us again you know further explore uh let us explore the uh data set a bit more so now let us take a quick look at the uh at our Target variable okay so we'll say Y is equal to DF stroke okay so this is our Target variable so let us Take a quick look at it so we will uh let's say you know we we we need we need to see the uh number of values here so we'll say value counts and let us say you know okay let us see this let us see this
let us see the different counts for different values here so we have two values 0 and one and these are the respective counts for it so to better understand its uh spread of these values I mean spread means you know uh the proportion of this values we'll Normalize it we'll say normalize is equal to true and let us take a look at it again uh okay normaliz it's not Norm it's normaliz okay so we can see uh this is the proportion uh 0.95 uh portion of uh I mean this stroke column is for zero and
only 0.04 portion of it is uh having one as value okay so there are there's a huge imbalance okay so for uh seeing it better we can just I think might multiplying this we will be Getting so as you can see 95 percentage of the data set uh for this stroke is zero and only 4 percentage is having one as uh value okay so we have a highly imbalanced data set okay so whenever you are trying to collect a data set for any machine learning application try to make sure that if it's a binary classification
problem both the classes will be and both the classes must have equal proportions okay in your data set so that means uh whoever collected Collected this data set should have included 50% of the data set with people who had heart attack I mean uh stroke okay so uh you should include 50% of the data set with people who had uh stroke that means you know one will should be I mean one must be having uh I mean at least close to 50% of the proportion of the data set okay so in our case in our
case we only had 5 percentage of the data set uh with uh class one okay rest of the 95% of the data set is is having class zero so we have an imbalanced data set and we need to we need to use some of the uh methods that is used commonly for handling imbalanced data set okay so because machine learning models generally I mean most of the machine learning models don't work uh that good with the uh imbalanced datet okay so just to visualize uh how big this uh difference is uh we can just maybe
you know create a histogram okay so we'll Use a common uh common Library known as blot link so if you haven't uh I mean if you using uh this code in your own machine you might have to install this uh separately plotly so I am importing plotly do Express as PX okay so this would probably do it and oh I have got a suggestion let us just check it what will give let's see huh okay we have got a chart uh suggestion uh know by Google collab and It looks pretty good enough okay so yeah
we can use this as well so um as you can see the proportion of One Versus zero is really I mean the difference between the proportion of one and Zer is really huge here okay so one thing we have to do while building this machine learning model is to use the correct metric okay so we cannot use accuracy as a metrics here because you know it will be misleading okay so you know the choice of wrong metric can mean choosing the Wrong algorithm as well okay so we can see that the target is cued and
you know uh the best metric for this binary classification problem will be area under the curve okay I mean accuracy will not be a good uh metric for uh an imbalanced data set okay because it will lead it it will give us misleading result because you know if it predicts uh all the time if it predicts zero it will still end up having 95% correct prediction isn't it so imagine you know It is Ting zero all the time it will always have 95% as accuracy because you know 95% of the data set is having class
zero okay so I mean all the model has to do to get 95% accuracy is to predict zero all the time if it does that it will get 95% accuracy isn't it so I is not a good uh metric for uh using this uh I mean metric to use for this machine learning model okay so we'll be using a metric like r or you know uh area under the curve okay uh so area under the RC Curve so I mean it is it combines the um I mean goodness of precision and recall Matrix okay so
it comb combines these true two metrics precision and recall which are better metrics for uh this kind of imbalanced data sets than accuracy okay so uh also we need to do uh some more uh you know exploration of our uh data set so we will just we have seen the numerical I mean we have seen the categorical data sets categorical features so now let us see the numerical Features okay so age average glucose level and BMI and we will describe it so as you can see you know using Google collab for learning purpose is really
good you know it gives us these suggestions okay so as you can see uh the maximum value maximum age of the person uh in this data set is 82 and the maximum uh glucose level is 271 maximum BMI 97 and minimum minimum age is zero something like that and minimum glucose level minimum average glucose level is 55 and minimum B BMI is 10 okay so uh we can also see some other things here so we can see the difference between the mean and the median here okay so let us see the mean of age is
43 and the median so 50th percentile so these are percentiles okay 25th percentile 50th percentile and 75th percentile okay so 50th percentile is also called as median okay so we can see the mean is less than the median okay so what does that mean so the mean is less than median means The uh Edge column is left skewed okay so it is skewed to the left side okay so that is what median greater than mean means okay and also uh we can see BMI okay BMI has a mean of 28 but its median is less
than that isn't it so what does that mean if the median is less than mean it means it is right skewed okay so it is right skewed so also average glucose level also has a mean of 106 but the median is 91 okay median is less so what does that mean it is right skewed Okay it has right skew so we can also see the skewness here uh so let us say you know I mean uh we can see it in numbers first and then we will actually uh we will actually draw something and or
let us say if we get a suggestion here we have got a suggestion so let us go with that so let us see it in uh figure itself so as you can see there's a right skew for glucose level okay so median comes somewhere here and the mean comes somewhere here okay so median is Less than the mean so if median is less than mean there is right skew okay it is skew to the right side as you can see okay and also AG has left skew isn't it so that means you know median is
greater median is somewhere here and mean is I mean median is somewhere here and mean is somewhere here okay so uh mean is less than median means left skew mean is greater than median means right skew okay BMI also has a right skew here so we have seen that here okay so that's About the uh that's about the skewness of these uh data these features so we need to deal with skewness as well okay so we'll use some uh standardization like standard scaler and also some power transformations to deal with uh this Q so because
you know most machine learning models prefer a uh bell curve okay so a bell-shaped curve that is what most machine learning models will uh prefer so you know it prefers a data set that will look like this I will so most Machine learning models prefer the Futures to have a uh curve that uh histogram that looks like this okay so a b curve this look like a I mean b Bell isn't it so most machine learning models uh prefer feature with this kind of a curve uh when we draw a histogram okay so that is
why we need to deal with uh skewness okay so we will uh use techniques like you know standardization and power transformation to uh make our features look uh similar to this okay so That's about that so let us take a look at the rest of the uh data set okay so we will say we will uh create a figure let's say PX dot let's make a histogram uh let us go with the suggestion okay let us just try the suggestion and see what it gives us so we'll say gender here uh we will put the
WID to 400 here let us just see what it gives us so as you can see uh this is the proportion of uh the male and female Uh here we can see that the count for the female is more than the male uh in our data set so now let us see the probability of getting uh a stroke based on whether or not the person is a male or female okay so let us say uh DF of DF uh gender and gender is equal to first let us check for the male uh male and so
if it's a male then we need to get the uh we need to see the stroke Okay so we we need we are basically getting all the uh patients who had stroke uh when he or she I mean when that person is a male okay so mean uh let us multiply this by 100 okay so let us see so as you can see it is around 5% okay so this means that uh a male gender uh in this data set has a uh probability of 5.1 percentage to get a stroke let us round it to
get a better understanding so we will round it Uh we need to round it here right so we'll round it here two two places so okay 5.11 percentage of chance to get uh stroke okay so males have 5.11 percentage of uh chance to get a stroke so let us do the same for female so let us say female so females has a chance of 4.71% to get strong stroke okay so that means you know a male uh I mean males have a higher chance of getting stroke According to this dat is it uh we can
see that males are having higher chance of getting stroke okay compared to females so let us again uh go and explore the other uh fatures just like this so we will say the next one uh we'll just copy this okay for the other uh other other columns as well so we will pass in hypertension here so we will say hypertension and let us see so as you can see the proportion of hypertension We have in our data set there are more people having hyper I mean not having hypertension than the people who are having hypertension
okay so this is the proportion of that data set now let us let us try to uh see this see the probability of getting stroke for if having hypertension so let us say it's equal to equal to 1 and let us see as you can see you know uh people with hypertension has a 133% chance to uh get stroke okay so people Who are having hypertension has 13.25 uh probability to I mean percentage to get uh stroke okay so let us change this to zero and see uh the difference so as you can see person
who doesn't have hypertension only has 3 percentage chance chance to get stroke okay so person who doesn't have hypertension has less chance of getting a stroke so similarly let us see the other feature as well so next one is heart disease Okay so let us uh draw for heart disase okay sorry uh not not here okay so let us draw the diagram first to see the proportion of heart disease heart disease also has a similar proportion uh person with I mean people with one heart disease is in low count in this data set than the
people with there are more people with heart disease I mean there are more people without heart disease in the in this dat set than people with heart disease so let us Check whether or not people with heart disease has the a chance of getting stroke I mean what is the probability to get stroke so we can see there is 17% chance for a person with heart disease to has to have stroke okay so 17 percentage chance is there for a person with heart disease to have stroke okay so let us check for not having heart
disease so there is only 4 percentage chance 4 percentage chance for a person without heart disease for getting stroke Okay so that's about heart disease now let us move on similarly for the other uh categorical features so ever married let us take ever married and see the proportion of the data set as you can see there are more people uh who are married than uh non-married okay so in this data set there are more I mean more people are married Okay so so let us do the same thing let us check whether or not a
married person will get heart attack more than non-married person so Let us say you know the person is married and what is the percentage of uh okay oh sorry sorry it's not like that it is yes or no it's not one or two it's yes or no okay so there's a six percentage of chance to for a person who is married to have heart attack I mean stroke okay uh both are same similar okay uh and only one percentage of chance for a person who is not married to get stroke that Means you know married
people get stroke more often okay at least according to this data set that's what it means okay so let's continue so what's the next the next uh categorical variable is work type okay so let us take a look at the histogram for that so as you can see private work type is more here and the all the other ones have similar proportion and never worked uh there's only very few people only 22 people in this data set have never worked okay so That's interesting uh data let us do the same thing uh for all the
people here let us uh do a loop here okay let us not copy and paste this sever time let us just uh do a loop here so let us uh let us see it all together so we'll just delete that we'll say stroke person ages um work type okay uh it has suggested us this code Let us just go by it so as you can see it is making it really easy for us okay so I will suggest all of you to use this uh same um I mean Ida while you are learning Google collab
let us just print it and see as you can see uh self-employed person has more chance of getting stroke okay uh uh I mean a person who has never worked has zero 0 percentage chance of getting stroke okay so your secret for not getting stroke is to never work okay okay uh just King uh So self-employed people according to this data set self-employed people have more percentage of chance to get uh stroke okay so that's about work type so what is the next thing what was the next thing I think it's said residence type isn't
it so next is residence type so we'll do the same thing here so we have two residence types so thankfully both residence types have a proportion that is equal okay so we have equal proportion of people here both uh both From urban and rural areas we have equal proportion here okay so let us do the same thing let us uh okay let us just uh do do this group by okay let us do this group by instead of work type we have resident type okay distance type so let us see okay so um according to
this uh people who are living in urban areas have more percentage I mean more chance of getting Stroke okay little bit more okay I mean the difference is not huge but there is a small difference okay so next is one of the interesting uh columns smoking status okay most people will be really worried you know whether or not they will get stroke uh because they are smoking so let us check that uh so before that you know I'm just telling you you know whatever result that you are getting is totally dependent on uh this data
set okay I mean this is not uh I mean this is this doesn't mean that you know people who are smoking or not smoking doesn't get stroke okay so this is just a data analysis based on this data set this doesn't prove anything or uh don't prove anything okay okay so let us see uh the proportion that we have here is there are more people who have never smoked in this data set uh than people who have smoked so let us check the same thing for uh for this data as well smoking status so we'll
just Replace this with smoking status and see okay so uh as you can see people who have formerly smoked uh has more chance of getting stroke than people who have never never smoked okay but uh as you can see the uh percentage difference is very few okay the difference is not that big but still you know uh if the data is to be trusted then obviously people who are smoking has a higher chance of getting stroke okay I mean the percentage if you are into Data analysis And if you know statistics then you know that
you know this is a really uh small percentage considering the fact that you know our data set only has uh this many number of rows okay so um let us continue let us continue so the next one is so we have seen uh all the categorical variables and their um I mean the percentage of chance of getting stroke because of different values in those categorical variables so now let us uh understand The actual uh dependency of these categorical variables with our Target variable okay so the degree of dependency between this categorical variables and the target
variable okay and we can measure it using a uh using something called as Mutual info score okay so we can import from um from a scalan uh from a scalan do Matrix let us import Mutual let's see if I get a suggestion yes Mutual info score okay so we can use this to get the uh dependency The degree of dependency between um the categorical variables and our Target variable Okay so higher value of mutual information mean higher degree of dependency okay and higher like you know higher Mutual info info score implies that you know we
can get a better prediction on the target variable if we use that particular categorical variable okay so let us check that let us check the info score for all the uh variables so let us again make the list Of all the categorical variables uh I guess we had this made before anyway so let us continue uh and then uh we got a suggest here let us try it out maybe um yeah let us try it out this is perfect so it is basically taking all the columns from this um list and it is checking the
mutual info score for each with this stroke variable okay and it is printing so this perfect let us uh go on with it uh okay but it is uh not really Printing it pretty well so we need to actually M do something like do 2 F I think this will do okay so as you can see uh we have here the mutual info scores for all these variables uh as you can see so the um actually the dependency for our categorical variables uh with our predicted our Target variable is Really low okay so as per
this Mutual scores we can see that you know the dependency between our categorical variables and our Target variable is really low okay only some of these features like you know heart disease hypertension uh and work type has a really really small dependency I mean our stock uh Target variable has a really small dependency uh with hypertension heart disease ever married and work type okay so it is not really Significant okay we don't have a high um like you know dependency uh between this categoric variables and Target variables okay so our categorical variables has almost no
effect on the target variable okay so let us uh do a similar kind of um like dependency visualization I mean let us see the depy for also our numerical features okay so we will uh we'll see the correlation Matrix here so as you can see uh we can see the Correlation between these variables okay so we actually forgot the uh Target variable okay we so we need to that's what we need to see we need to see the correlation between these numerical variables and our uh Target variable okay so let us say plus stroke I
think this will work so as you can see um so you know you can see there's a really I mean this a slight or there's a small positive correlation between age and stroke which is obvious Actually as age increases you the your chance of getting getting stroke obviously increases and also we can see uh average glucose level also has a really small positive uh correlation between stroke okay obviously gluc as glucose level increases your chance of getting stroke also increases uh BMI doesn't according to this data set BMI doesn't really actually have uh you know
a direct correlation between uh it is nearly zero okay so it doesn't have an Inverse or uh it doesn't have a positive or negative correlation with stroke okay it's a it's near Z okay so age does have a small small uh correlation uh with stroke okay so actually we are done with our uh data analysis part okay so what have we learned we have learned that you know people uh I mean I mean as age increases stroke increases I mean chance of getting stroke increases also average glucose level has a really slight chance Of uh
causing stroke BMI doesn't have any much effect on stroke and uh as we move uh move to the top you can see the categorical variables doesn't really have much uh influence on the on whether or not you are going to get stroke or not uh as per this Mutual info score but uh when we move up we can see that you know person who are small formerly smoked has a slight more slightly more chance of getting stroke than person who have not smoked uh similarly you know Person who are living in urban area uh this
difference is really insignificant okay so let us not talk about that and a you can see self-employed person has a slightly more chance of getting stroke than other kind of uh other work types also uh person who has married has a slightly higher chance of getting stroke than a non-married person and also we also saw that you know person who had heart disease had a higher chance of getting stroke than uh person who didn't Have heart disease same with hypertension okay and also uh as I mean in terms of gender a male had a higher
chance of getting stroke than female okay I mean it's it's it is also really really insignificant okay so that's all about our uh data analysis part also we know that you know we have some skewes to deal with also some null values to deal with you know here we have some null values to deal with and we also have in our Target uh variable we have An imbalanced data set okay so we need to deal with all of these things so next step is dealing with that okay making the machine learning model uh you know
while dealing with all these things okay so uh I have just written down these things here uh that I have just mentioned about the features so let us uh start by dividing the getting the column separately the numerical and categorical variables uh as we have mentioned we need to do some Transformations right so we need to deal with null values uh skus and also uh we need to apply uh some methods to deal with imbalanced a set as well and also for the categorical variables we need to convert them to uh um we need to
convert them to numerical ones okay basically we need to enod it so we have some categorical variables here we need to enod them as well okay and also one more thing uh as you can see uh the numerical values have different scales isn't it so This uh okay what was the descri I mean details okay so BMI ranges from uh 10 to 97 um and average glucose level ranges from 55 to 271 okay also age ranges from 22 to 82 so uh these things have different ranges so we need to make it into a a
uh we need to standard I mean we need to standardize it okay so basically we need to scale it to a similar scale okay we need to make it to a similar scale alongside uh dealing with the Skewness okay so those are the things that we need to do scaling uh Power transformation to deal with scenus uh and imputer simple imputer uh for dealing with uh null values okay so basically removing the replacing the null values with some strategy like mean or medium also one hot enoder we'll use we'll be using one hot encoder for
encoding the categorical variables okay so those are the things so let's say um let's divide the Numerical variables and categorical numerical is equal to so so these are the numerical variables and for categorical categorical we have this and so I will be using pipeline so uh pipeline is something that will allow us to do um Transformations on all these data sets multiple Transformations on Our data okay so that's what pipeline is used for so from also I have libraries that we will be using uh I will explain each one of these as and when we
use them okay so uh let us now apply these Transformations that we have mentioned so BMI has null values right so we need to deal with that so the method that we will be using to deal with null values is called uh simple imputer okay so simple imputer and uh takes a strategy and it will Replace the null values with that strategy okay so let us create a uh let us use something called as a column Transformer I will explain it let me just type it in uh okay so a column Transformer is something that
uh takes in a column or a set of columns and apply some Transformations okay so that's what a column Transformer does so it it it takes in uh Transformers which is an array of uh tles okay so we have an array of t dles and inside that tles We will mention like this okay so we will mention uh a name for our Transformer and what transformations to do and on which columns okay so name the the transformation okay name transformation and uh on which columns the transformation should be done so these are the three values
that we need to pass in uh as a tle to this Transformers Transformers array okay so the column Transformer we apply the Transformations on particular columns Okay so that's what column Transformer is used for so we have more Transformations here not just power transformer uh we need imputer uh to convert the null values and then we need the uh power transformer right so we we have two Transformations here so for that as I have mentioned before we will be using pipeline so pipeline lets us to do multiple transformations in a single uh like we can
put together multip Transformations uh for a column okay Using pipeline so inside pipeline the First Transformation is imputer right so first of all we need to impute it so as I have mentioned we will be using symol imputer and symol imputer will basically take in any n values and uh replace it with a strategy so uh we will type in here strategy and the strategy that we will be using is median so what happens here is that the the simple imputer will uh Will convert all the null values in any of these columns that is
mentioned in this numerical array uh basically we have null values in BMI so it will it will uh replace the null values in BMI column with the with the median of all the values in uh BMI column okay so that is our strategy here so inut is the name of the Transformer simple imputer is the uh strategy okay simple imputer is what we'll be doing so that's the first St uh so yeah where should I put the comma Okay so the next transformation in this pipeline is power transformer right so we need to do power
transformer uh so why why are we doing this we are doing this to uh turn the skewness okay so we are doing this to deal with the skewness so skew data set uh might not perform as good as and a normal distribution okay a normal distribution is also called as goian distribution so uh power transformer will allow us to Convert skew data sets into normal distributions okay which are much better for machine learning models to deal with so I'll show you again what normal distribution is as I have mentioned before so as you can see
so this is a normal distribution okay as you can see this is a normal distribution and machine learning models tend to do better on normal distribution the blue one is normal distribution the other two are skewed the green one one Is right skewed and the red one is left skewed okay and machine learning models uh does better on normal distribution data sets so that's why we are doing power Transformations here so we will also do uh one more thing we will say standard I is equal to true so after power transformation we will also standardize
it so that's also something that I have mentioned before why do we do it because our numerical values have different ranges isn't it so the range For an age will be between 0 to 100 or something like that but that is not the same range for a a variable like BMI or average glucose level right average GL glucose level will be having a uh much higher range of values isn't it so the range is different and you know in that case what what happens is that you know I will show you uh what will happen
so as we can let's take a look at the data set so in in the case where uh different Futures have different scales what the Machine learning model will do is that it will give more importance to the future that has a higher value okay so so some models okay not all models some models tend to give more importance to the columns having higher values okay so it can go both ways so difference in scale will uh mean that you know the model will treat these different Futures differently okay but we don't need that right
I mean we don't need that to happen uh on its own I mean obviously we Can uh tell the model to give little bit more importance to one of these columns but that control should be on us isn't it so we need to we have to control those uh things right so if you don't scale all the features to a equal scale what happens is that the model will automatically assign importance to importance differently to different columns okay so that control should be uh within our hands right so we should be the one who is
telling the model Which features will be having higher priority the model should not be uh Des in on that based on the values so that's the reason why we are going to make all the features all the numerical features in the same range okay so that's why standardize is equal to True is given here so after power transformation after making it to normal distribution it will standardize it okay so those are the uh Transformations that we need to do on the numerical columns these three Columns we will simple imputer we will use Simple imputer to
replace n values with the median value then power transformer with standardization okay and next is uh categorical variable isn't it so next is our categorical variable and we only need to uh do one thing enode it so this categorical variables that we have here will be encoded to numerical values like how like I have explained before column ever married will be converted to two columns Okay ever married yes and ever married no and uh in whichever whichever rows ever married has an a it will be uh I mean the ever married s column will be
will be having one and wherever it is no the evermed s column will be having zero there okay so this will basically convert um this binary uh digit column to two columns okay so if the column has more than two values or if there are five values it will be converted to five different columns okay so that is how Usually imputer one I mean en corders Works uh I believe one enod also so just to make sure let's just search for it one enod working so as we have mentioned uh it's the same thing it
will be creating a new binary columns for each unique category in the data just like how I have mentioned okay so yeah so that's what one hot enod will does so those are the two Transformations that we will be doing so let us just see if there are any further Transformations Needed uh okay so those are the two column Transformations okay so after that one more thing we need to do one more issue we had what was that we have imbalanced data set isn't it so we need to deal with that as well so that
uh imbalance I mean the method that we'll be using to um deal with imbalanced data set should be applied to the whole data set okay so for that we'll be using pipeline again uh pipeline is something that is used to uh give transformations To the whole data set okay so multiple Transformations okay so in the pipeline these are the steps so I have received the correct uh suggestion actually so first of all we'll be using this Transformer that we have made and you know that will be that will be the first step so our data
set will go through this Transformer and do this all these Transformations and after that we are using smot so I will explain what smot is so smot is the algorithm that we will Be using for dealing with imbalanced datet Okay so this will basically do one thing okay so it will basically balance the data set by either increasing the number of the minority class so in our case minority class is what uh the people with stroke isn't it so the people without stroke is the majority class zero is the majority and one is the minority
isn't it so uh because of that uh what what SM does is that it will it will balance out this okay so it Will either increase the number of uh majority class I mean minority class or decrease the number of majority class to make these two values equal at least uh similar okay the number of values similar okay the proportion similar so that's what smot does it will balance out the um Target variable so that you know we will be having equal number of people with uh with stroke and without stroke in the data set
so that's what smot does smot is the algorithm that is Used for that also the full form of smot is synthetic minority over sampling technique okay so basically synthetic synthetic means it will be creating synthetic data not the original it won't be duplicating the original existing data will create synthetic data okay new data uh for minority minority class okay so it will create more uh data for the minority class uh and oversampling technique okay so it's is a technique That is used for increasing the number of minority data okay basically balancing out minority and majority
classes okay so that's that actually uh kind of completes our PIP plan okay so our PIP plan for uh our machine learning model so now is the time to select the machine learning model so we'll be using a common machine learning model one of the common machine learning models and also uh or maybe few of common uh common machine learning models and also one um Like I won't call it Advanced but one emble model okay so one normal machine learning model and one Ensemble model Ensemble is nothing but collection of uh models okay so it's
a collection of models uh so we'll be using Ensemble model like random Forest okay so we'll use random forest and also uh we will use what something like maybe you know linear discriminant analysis or maybe uh you know something like logistic regression okay so let us first import Those three models okay so we will import let us do it in the next uh Next Step okay so we will say random Forest classifier then we will say scal and Dot dis not discriminant I'm waiting for the suggestion actually okay it's not suggesting me anything so I'll
just copy and Paste so we have imported the three models that we have decided to use okay so R Forest classifier linear discrimin analysis and also uh logistic regression okay so this these two are some of the base models and this one is a I mean Rand Forest classifier is uh an ensemble model okay so these are the three models that we'll be using so we'll write a function that will return us these models okay in list uh with names so we'll say def get Models and we'll say models comma names is equal to we'll
create two list list and we'll say models do append logistic regression so I have imported all the models here I mean I have written the function for uh returning all the models with its names here so now what we will do is now we will create um like the X and The Y values basically the target value and the um the tra the values that we are using for training so the target will be what the column stroke and X that represents the training data will be all the column expect uh except the except the
uh column stroke except the stroke column so X will have all the column except stroke column okay so that will be X and Y and we will also write a function for Evaluating model so we'll say evaluate evaluate model you'll take in XY and the model for evaluation and we'll say uh cross validation is equal to repeated stratified kfold cross validation I will explain this in a bit and then we need scores so we'll take uh scores from Cross Val score we'll pass in the model XY and this scoring is uh not accuracy we'll be
using as as we have discussed R A okay So that will be the scoring that we'll be using and I have also mentioned why we are using r a um because the area under the Curve will give us a better measure than accuracy okay because for imbalance that is set that is how uh that that is what does better okay so that's why we are using area under the curve okay so um so that's the function that will return as the score now I will explain all of this so as mentioned before Repeated stratified uh
cross validation is a cross validation technique that is used for evaluating the performance of the model okay so here n splits is equal to 10 means that it is a 10-fold cross validation so here K is equal to 10 and uh in a 10-fold cross validation the data set is spit into 10 parts okay 10 parts or folds so the model is trained on nine of these folds and tested on the remaining one fold at a time okay so that's what it does and this process is Repeated 10 times okay so each time nine of
the folds will be used for training and the remaining one is used for testing okay so and and also n repeats is equal to 3 means you know we'll be repeating this 10-fold cross validation process three times okay so it will be 10 into 3 30 okay so 30 uh training and testing will be done okay so after completing one round of 10-fold called cross validation the data is shuffled reshuffled and the process is repeated Two more times okay so this ensures a more robust evaluation okay so that's uh it reduces the variance of the
evaluation metrix so that's what that is and random state is equal to 42 I have just given right now so that you know we we will both be getting the similar similar kind of results okay so that's what that that is and this cross while score will be used for a Cy cycline function that is used for um you know evaluating the model using the specified Metrix that is Roc Au curve okay so area under the curve okay so it's like I mean Roc means receiver operating characteristics curve okay so it is a it is
a widely used binary class classification evaluation metric okay so it tells us how well the model separates the two classes okay Stroke versus non-stroke so that is why it is much better than accuracy okay so this gives uh the a measure of how well the model separates two classes other than just Accuracy okay so a a higher Roc a a value that is closer to one indicate a better performance okay so that is what this um cross cross validation score will do okay and this technique that we'll be using is the technique that we have
mentioned here repeated stratified kfold cross validation so one more thing is one more thing that I have mentioned is I haven't mentioned is stratified okay so this stratified means uh the whenever This splitting when whenever the uh repeated stratified kold cross validation spit the data set it will ensure that uh each fold will be having approximately the same proportion of samples from each class as in the original data set okay so this ensures that each training and testing set has a class distribution that is similar to the entire data set okay so for example if
your data set has thousand samples and 900 samples belong to class zero and 100 samples belong to class one so in a stratified kold each fold will contain approximately 90% of class Z and 10% of class one okay so it will maintain the original ratio of uh the classes so that's why stratified kold cross validation is used okay so that is what uh our evaluation function will uh look like okay so now let us get into uh training these models and evaluating so what we will do is actually we should move this into maybe the
next line I Think so that we can just run this and we have X and Y here so we'll get the models and the names models names is equal to get models and we'll just mention uh we'll just create a list for storing the results of our uh evaluation okay actually we made a slight mistake so we need to First apply this pipeline okay so we have just created the pipeline but we haven't uh used it on our data set so we need to Use that first after creating the pipeline and only then you know
we can uh loop through the models and apply our models through it okay so let us do one thing let us uh or maybe we can do this okay we can just cut that from there we we will rerun this whole thing okay so that we won't make the mistake so we can put this inside the loop okay so we can just pass it inside the loop group and we will add one more step here okay so inside the steps we will add one more Tle and this time what will be that it will be
our model okay so that is one thing that we can do and inside this we'll take models of I okay so this will basically apply these Transformations uh use smot and pass in our data set for evaluation to our models okay not evaluation for training to our models so that is what uh this pipeline will do so instead of models here we will pass in our pipeline here okay so that's what we will be doing and We also need to print this right so we need to print this results so how can we do that
so we'll say print uh I have just received a suggestion this is really good okay so this suggestions are really doing great okay I think I need uh what do I need there is some error okay maybe NB do mean right n b do standard Okay okay I think that will do that uh we need to import NBI I think import n by as INB okay so that will remove that error I believe isn't it okay so that's gone so this will print the scores um for us actually I have a better one here okay
so this will print it better alongside with with the names okay so that's that so let us I think this is Enough we can just run it and we can get the results I believe we need to run the whole thing again if we have made any mistakes you know this will ensure that the steps will be applied correctly okay so uh nothing we have just you know get we are getting all the models alongside with its name from the function we have written here we'll be using three models logistic regression linear discrimin analysis and
random Forest classifier okay with an N estimator 100 so N Estimators means each estimator is a model so Rand forest classifier in default uses decision trees as its estimator okay so decision tree is a machine learning model so it will be using 100 decision trees and it will average out the result and it will return us okay so that's what random Forest classifier will do basically it's a forest of trees okay so that's all it is so uh basically we are looping through these models and we are taking Each models and you know we are
creating a pipeline and inside that pipeline we'll be doing the transformation we'll be us using smot for uh dealing with imbalanced data set and also after all that the data will be passed through the model and we'll be getting the results okay so this full pipeline is passed into this evaluation our evaluation function that we have written okay so I guess this will be working Well so let us see if it works so we'll just run it all okay so actually we received an error here so it says all intermediate steps should be Transformers and
Implement fit transform okay so uh so the problem is our smot algorithm uh is imported from uh this Library IM Larn okay so that is something that I have done without even without thinking about the pipeline so our escaline our cycline pipeline Actually expects uh all the Transformers to be uh I mean all the intermediate steps uh to be Transformers okay so that implements fit and transform but you know the smot from imbalanced learn library is not a Transformer okay so that why we are getting this error so instead of that we actually need to
do something else we either need to do is uh use a pipeline from uh the same Library we need to use a pipeline from IM learn or we need to use smot From some other Library so let's see we can do so let us do one let us import the pipeline from the um same Library okay so we will import pipeline from IMB Larn itself so imarn is nothing but an extension for cycle Larn okay so IM learn. pipeline we will import pipeline so this should work better now let us see we'll run all of
it [Music] Again no it's not working well okay so power transformer uh right now okay so the problem is that you know um column Transformer I mean pipeline cannot be um pipeline cannot be used inside column Transformer okay so it should be py line pipeline here but for the next pipeline the overall pip P line we can use what uh IM Lear pipeline okay so here we can actually use IM learn Pipeline so it will be IM learn pipeline okay so we'll say im pipeline okay so this uh this should solve the issue let us
see okay have another isue great uh you cannot import name I oh sorry okay uh should be we cannot do like this okay let us run it and see H Okay basically we are missing a parenthesis somewhere okay so this should be like I have mentioned should be a tle okay so here I should mention like power comma the transformation yeah so that's how it should be like just run all again see uh these mistakes will happen Okay so whenever you're doing something from scratch you know there will be it Is bound to have mistakes
okay so we have successfully run it and we have received the RC scores for our linear uh regression I mean logistic regression and uh linear discriminant analysis okay so we can see one has 0.83 one has 0.837 so LDA did actually better than uh logistic regression let us wait for the uh random Forest scores Okay so actually um the random Forest did worse than uh LDA and logistic regression okay so this could be used to uh due to many things Actually we haven't explored all all the uh you know hyper parameters of random Forest we
are just we have we just mentioned n estimators to be 100 so we can actually um actually change some of these parameters add more parameters and try out actually random Forest classifiers work better uh when using grid search or rized search CV algorithms okay basically trying out different hyper parameters uh is the way to use ROM Forest classifier okay so in Cases like this uh LDA and logistic regression tend to do better job so uh from this uh I have decided to pick LDA as our algorithm uh moving forward for building the application okay so
our goal is to uh make an end to end machine learning project for stock uh prediction isn't it so we have done the explorat data analysis and we have you know identified the steps for building a pipel planine and also uh you know training multiple models and checking This scores isn't it we we learned how to deal with imbalanced data set using smot algorithm uh so we have learned quite a lot now let us uh quickly go through the steps for building the application okay so we'll be using react for the front end and also
we'll be using a sybol react project for frontend and we'll be using flask for making our API our back end okay so let us uh go to vs code V visual code uh Visual Studio code and for making the application okay So now we will be creating the application okay so for that um Let Us open the terminal and here okay I will choose CMD okay so we will say mkd flask react app okay so as I have mentioned at the start of this tutorial that we will be making the uh front end for our
application in react and uh the back end in flask okay and uh also I would like to mention that you know I won't be going in too much detail about The uh front end because you know our goal is here to um understand how to make a full stack uh end to end machine learning web application okay uh not just a react application so uh first of all make a directory named flask react app and inside that uh we will do one thing we will open this in terminal and here we actually need to um
enable an environment okay so I have already created a python environment using Anaconda so if you haven't already you can watch any tutorial online on how to create a python environment using or AA environment okay anonda environment so we have to switch to this enrollment first so I have opened the application open the folder in vs code and uh now the folder is empty so let us actually create uh our backend file here or let us say let us create another folder back end okay so file let's create another folder let's say back End and
inside this let us create a file named app.py okay and here here we can choose The Interpreter so I will be choosing uh an interpreter that has I mean an enrollment that I have already made using Anaconda okay so this this environment has a python interpreter so that is The Interpreter that I will be using okay that is the python interpreter that I will be using and it is 3 uh1 12.4 okay so you can choose any Uh python interpreter here uh it will be better to use the one in your uh G enrollment okay
as I have mentioned before you have to make an enrollment before proceeding because you know we'll be going to install all the necessary libraries in that environment okay so that is better instead of installing it uh installing it globally okay okay so in my case I have already installed all the necessary libraries so if you haven't installed then go to Anaconda Powershell prompt and here you can actually say k activate first create your environment okay so you have to first create your environment Conta create envirment and then you can activate it by saying cond activate
environment and in here you can install you can either use K install or pip install I would suggest using K install inside cond environment if you're using pin stall try to create a normal python environment okay like Python 3 m uh V andv okay viral environment and uh you know you have to install libraries like you know flask uh probably you have to install psyit learn uh you know psyit learn then you will be have to install pandas so and IM learn IM learn so these are the libraries that uh IMB loar so these are
the libraries that you would have to install uh for uh making this application okay so first of all Activate your environment and install these packages okay and choose the same envirment uh same envirment interpreter uh in the vs code okay so those are the things that you have to do so before creating the API uh you know we have to do one thing so uh before that API is something that will connect the front end with the back end okay so it is what connect the um connect what the what the user sees uh with
the actual functionality okay so the back end uh The app.py will be the one getting the data set uh getting the data information from the front end from the user and running the machine learning model all this happens in this app.py okay so before that one important step uh we have made the machine learning model we have trained it but we haven't uh what we haven't saved the model right so we'll just create a fun create another file called training. Py and in here we will put the same code that we have used uh from
the what in the uh collab and we will copy that copy and paste some of those codes and you know we will instead uh this time we will save the uh model okay so I have imported job lip so this is a library that we'll be using for saving the model okay so so yeah the code we have already explained we have already seen the code it's the same code that we have used for training the model uh only one change Here is that instead of three models we are using the final model that we
have agreed on uh the linear discriminant analysis so we will be choosing the LDA model here okay so we don't have to print anything here um so this is the model that we have agreed on the final model that we will be using so we will use that model and here uh you can see we have called this dump method from jblp and inside this we will be saving the uh machine learning Model uh as name stock prediction model okay so this is this is how we will be saving up machine learning model okay so
after running this our model will be trained on the data set and it will be saved here okay so another one important step that we have missed is uh actually getting the stock data set uh so probably have to change the path as well okay so we will get the path from here and in here um yeah Let me just see if it's still there yeah okay so we will run this we will we will call Python and then training dopy okay uh okay say Pyon okay we are getting some errors okay of course I
need to CD into the folder back end and then we will run this okay so this will actually train The model and it will save the uh model in the same folder so it is basically training now and soon enough okay I think it has finished training so you can see it has saved our model here stock prediction model JBL okay so we'll be using this model in our uh back end code okay so let us write the code for the backend so we'll say from flask so we are using flask for making The apis
import flask we will also import request and jifi and we also might need pandas I think just for converting to data frame import pandas as PD Al from Jo bliip import load from flas course import course so course is Necessary because you know uh course is something that will allow us to actually access uh things that are not in our own network okay so cod's full form is cross origin resource sharing okay so it will allow us to share resources uh from coming from different Origins okay this will come in handy and we are trying
to connect the connect the uh back end with the front end okay so the back end and the front end sits on two different servers I mean if it sits on two Different servers then for communicating between those two uh front end and back end we need this origin resource sharing uh enabled okay in the back end okay so only then you know the back end can receive data from uh coming from different uh server okay so we'll sayot the train model model so if you wonder you know why I'm getting suggestions like this then
I am using something called tab 9 AI okay so this is an extension that I Using so you can also install this extension uh it will be pretty handy okay you can go to extensions and install tab n AI okay so load the trained model and here we will say model is equal to we will get the load function and from here we will load the machine learning model now we will initialize initialize the flas app okay initialize the flas cap then here we say app is equal to FL name and as I have mentioned
we need to enable course okay cross origin resource sharing okay so this will enable course so we have initialized the flask application now let us uh write the apis so as I I'm getting this suggestions beautiful suggestions of because of tab n AI okay so we have created a route called predict and the method is post so uh the user will be if the method here is post that means that you know This API will expect some input from the front end okay so post means someone is posting something from the front end and we
are getting it here okay so this predict API will get data uh I mean get data that is posted from the front end okay so if if it's get here then you know the user is asking for some data if it's post here then the user is sending some data okay so that is the difference between get and post so def predi here we will say Try uh we'll get the data data is equal to JS o n no no uh request dot JS so the data is will be coming as a JS format okay
from the front end as js1 format so we getting some error here okay we need an expect here I mean accept here every try should have an except okay exception let's see so we'll just return jifi error uh let's say 4 500 okay okay so request of JS uh we'll get the data from this and this data needs To be converted to data frame right so because our model uses data frame so we need to convert this data into Data frame Json data into Data frame so this is how we convert JSO into Data frame
P to data frame and pass in the data as array okay and we will say prediction is equal to model do predict we will pass in the data frame here or let's say zero so uh this model predict the zero um value will be our Prediction okay so we have received the prediction from here uh we can just print it if you need for debug debugging purposes so we'll say prediction thisal to prediction okay something like this or let us say can do it like this as well I prefer this okay um now after receiving
the prediction after getting the prediction from our model we will return this to the front end okay so return JS uh we Will return it in Json format so JSI prediction and uh we are Js I mean we are returning this object as a JSO format to the uh front end okay and this 200 means it's a success okay so we are saying we have uh successfully made the prediction and we are returning it and we are sending this status this is a status code 200 means uh it's a success 500 means it's a server
error okay so we are sending it back so that's all uh with the API we are only we only have One API predict API uh you know for getting the data and returning the prediction okay so we will also write one root API so app do root and this if someone goes to this rout they will get a welcome message just just for debugging purposes okay just to see if our API is working correctly if we go to this route you know we will get this message printed so now we will say if name is
Equal to to main now we will run this we'll write type the write the code to run this okay so we will run this in Local Host host is equal to 0.0.0.0 and we'll mention the port usually backends will run the run in this port uh Port debug usually we put 5,000 as the port to run backend locally okay debug is equal to two Okay so okay so I think this will work now so Let us try let us run this so we'll say app.py okay I think this is running so in order to just
test it like I have mentioned if I go to this uh route we will get this message welcome to stock prediction API okay so we have successfully um made our API run okay so now it's time to create what create the friend end okay so just like the uh creating this back end uh front end is also uh going to be very simple but you Might not be able to understand most of the code so I have already written the code I will just copy and paste it and then I will uh try to explain
some of it okay so we are our focus is not really on the front end okay because this is a purely machine learning tutorial uh on how to create an end to end machine learning application okay so uh for this actually you need to install uh node package manager okay so in order to install node you have to go to this uh Nodejs um website nodejs download uh package manager page and here you can uh do two things so if you're using Linux you can choose Linux here and uh I will be using the LTS
version so this is longterm support version and here you can choose NVM or fnm so I mean uh I believe believe NVM is installed in your Linux machine in that case just type in uh you know this uh command copy this command and paste to your terminal and run it okay So since I am using Windows uh I will use a pre-built installer and you know I will click download here and it will download uh to my Windows machine and then I will install it from there okay so uh kindly watch any tutorials if you
have any doubt on how to install nodejs just comment it down I will uh definitely help you out okay so you have to install nodejs to move forward uh with installing react okay so after installing node uh they will install React application here okay so I have already um cded into the uh out of this backend folder uh actually I need to get into this flask react folder so inside this flask react app here is where I will be running the command to install uh this react app okay so it is npx Type in npx
then create react app and uh we will type in the app name so this will be like we'll say friend end okay friend end so this will create uh the react application for You okay so it will take some time so it is creating I mean installing react react Dom and react Scripts so now as mentioned here in the terminal as suggestions we will go to friend and and then we will say npm start okay just to see how this looks like so as you can see it is getting started so it has started the
development Ser server and it has given us this Local Host where the front end application is hosted so we'll go to the Go to it and see our react application so this is how our react application looks like now uh you know we can see that you know uh there is this react icon here and uh learn react link is here and text is here okay so we'll change all of this and we'll write our own custom code so let us explore the code further so we will go to uh frontend folder and inside this
SRC folder so we can see here there is some already written pre uh pre-written CSS Uh here we will just remove all those and we will also we can also see some of JS written here we will uh other than this export we will actually we will remove all of that we'll save it now this will definitely crash your um react application and we also have some index CSS here we'll just comment it for now and this logo we don't need this okay anyway so this is how react application will look like I will not
go in detail about this so basically uh you Know whatever code that uh we are writing that the friend end user need to see it will be written here okay in in the app.js and what all styles we are giving to our application will be written in app. CSS okay so those are the things that you need to know you need to know right now so I will now just copy and paste the CSS that I have already written and also the JS code and then I will explain so I have copy and pasted the
CSS and JS Now let us just go to the website and see our application so as you can see our application is running in uh Local Host 3,000 as mentioned so I have copy and pasted all the HTML uh I mean all the JS and CSS files now I will explain uh what I am doing there okay so as I have mentioned previously I will be leaving the code to this uh in the description you can get the code from there here uh as I have mentioned I won't be going in Detail about the front
end part okay so I'll explain the ma major part here the important one so that is sending the uh data from the front end from our application here from this form here to the back end and getting the response okay so that is the important part here I'll just refresh again so that is the important part here so that happens here okay so we are saying const response so response is equal to await fetch so we are waiting and we are trying to fetch Some uh data from the front end I mean from the back
end by sending some data to the back end okay so we are sending some data to the back end here and you know we are getting some response from the back end okay so what are we sending here we sending to uh we are sending data to Local Host and the port is 500 5,000 and the API is predict okay so we have created the predict API here isn't it so we are hosted we have hosted it in Port 5 5,000 and we have created this Predict API and this API receives some data it is
post so ites some data uh here okay so here we are receiving some data so the user has to send some data okay so what is the data here the data is in post format and we have added some headers here we are basically saying that we are sending the data in JS format and this is the body this is the data okay so what is the data it is form data okay so what form which is the form the form that contains Gender age hypertension all these all these form field that we have that
we can see here okay so the moment I fill in this value and click this predict stroke button the form data will be collected from the friend end this form data will be collected from the FR end and it is sent as a JSO js. string ify will convert this to JS format as a JSO to the back end okay to the back end to this API okay so this API will receive this data Here this data here and it will convert to data frame here and this data frame is passed on model predict here
and it will get the prediction result and it will return back in JSO format okay so once the user get this data return back in JS format here here is waiting for response okay await response. JS it will get back this result here and we will alert the user we will use the alert function to just create an alert alert box here that you that you might have Seen in uh some websites there is an alert box that is provided from the browser itself so we are alerting the user sir by saying predit stroke uh
this score is equal to this okay so that's the major part that you have to understand here okay okay so there is one mistake one small mistake that we have done here uh so we are sending the data as prediction here isn't it and but we are expecting uh it as what result do stroke Here okay so uh so this is the same key that we have to use here okay so we have to use the stroke key here also one more thing uh um so this will be in string format right so we need
to convert that to integer as well so we'll convert it to integer and then we will send it as Json dot uh in Json format okay so we have to run this again uh we'll say control C to stop it and we will run the back end again okay so this will oh I think I haven't saved it we have to stop It again and run it again okay so now uh okay one more thing few more thing that I will explain so the form that I have mentioned is created here okay this is the
HTML part of the uh JS file of the reactjs file we don't have to worry much about it so this is where I have built the form okay you can see the gender column I mean gender select option here the age input option here in the input tag and the hypertension Select box so all these things are here you don't have to worry much about this HTML CS part so if you need to learn about how to create a react application how to write HT ml CSS code then comment it down okay in the comments
so if I'm going to explain all of these things in this tutorial it will it is going to be you know more than two three hours okay so uh I have explained the important part about how to how we are sending the data from the front end to the back end And how the frontend is getting the data back okay so that is the important part here uh so uh if you understood all of that now is the time to test the application okay so we have created the application now let us test it okay
so so let us enter all this value so I'm hoping for a uh positive stock prediction so for that let us enter all the all the all the you know what uh maximum values here okay so all the worst case values here uh so that you Know we make sure that you know this will receive and we will receive one as the result so we'll enter all the high values here so hopefully when I click this after some time we have received an alert from from Local Host 3,000 from the back end that says I
mean from the front end that says predict strock one that means the user uh is likely to get stock in the future okay so similarly now now let us enter all the um all the minimum values okay all the uh low very Low values let us say 20 a 20y old female with no hypertension no heart disease not married what type is uh let's say you know he's a child let us change the age to let us say 10 then leaves in rural area as a glucose level of just 80 smoking status never smoked and
BMI is7 something like that let us click the predict score and we can say we have received zero okay so our machine learning model is working successfully it has given us uh you know When we have entered the lowest values it has given us stroke as zero that means the person is not likely to get stroke and when we have when we have entered the higher values we received stock us one right so our machine learning model our web application uh that uses machine learning to predict stroke is working correctly okay so that's all about
this tutorial I hope you enjoyed it I know that I have went a bit fast in the Application building part but it is also because you know this tutorial is all about making an N end machine learning application the focus is on machine learning so if you want to know how to build uh a front end application like this then kindly mention that in the comment box I will be surely making another tutorial about it okay so I hope you enjoyed uh this I'll see you in the next tutorial until then Happy coding