We just show you?
How do we load the pickle file?
Because we need to do the prediction, right?
So how do we load the pickle file?
That is very much important to show, because at the end of the day when we create a end to end Streamlit
project.
So we definitely require all the pickle files.
So in order to load the pickle file.
So first of all, uh, um, what I have to do because see here I now have three pickle files.
I have all my model trained.
Now I have to make sure that I load that particular pickle file and I do the prediction right.
That is what I have to actually do.
If I don't do that, then it will not work out right.
So let me quickly go ahead and import all the libraries again.
So let's say that I'm doing it in my new file okay.
Or let's consider a new file.
So here I will say prediction dot ipynb okay.
Here the first thing first I will go ahead and import this.
Select the kernel okay.
So here you will be able to see that I'm going to execute this okay.
Now we are going to load all the trained model right.
So how many trained model we have.
So load the an trained model then um scalar pickle file and the one hot encoding pickle file also.
Right.
One hot encoding.
So we'll load this.
So I'll go ahead and write mode model is equal to load underscore model.
So here is what we have imported see from TensorFlow Keras dot models import load underscore model.
So here I'm going to write load underscore model.
And here I'm going to take my model dot h5 file okay.
When I probably go ahead and use this here you'll be able to see I will also go ahead and load my load
the encoders and scaler.
Now in order to encode, uh, load this I will go ahead and use with open quickly.
Let's go ahead and write label underscore encoder underscore geo dot pickle file.
So this will be my pickle file.
It will we will be reading this time in the read byte mode as file.
Because pickling is nothing but it is a deserialized format, right?
We can serialize it, we can deserialize it.
So here I'm going to basically you go ahead and use this label underscore underscore Geo is nothing
but pickle dot load this specific file name okay.
So here is what I get.
This particular pickle file over here okay.
And similarly I will go ahead and do the same thing for the gender and for the scalar.
Okay, so here I have my gender and for my scalar.
Now let's take some input data.
So I will take some input data.
So this I will go ahead and execute it.
Uh label encoder underscore geo.
What is the name that I've given.
Label encoder uh underscore gender.
Sorry.
It should be gender not geo.
Okay.
Oh, no.
This pickle file should be my geo pickle file is what?
Uh, one hot encoder.
Geo.
Right?
Not label encoder.
So here I'll go ahead and write.
One hot.
Let me rename this and let me copy this entire pickle file okay.
So here I'm just going to go ahead and write one underscore hot encoder underscore geo dot pickle file.
Now let me go ahead and execute it.
Now it works absolutely fine.
Right now I'm going to take some example input data.
Because based on this input data I'm going to do the prediction.
So here I have written credit score is equal to 600.
Geography France.
Male.
Gender male age 40.
Tenure 30.
This this this.
There.
Now when I'm giving this particular data, the first thing that I need to think is that how do I convert
this particular value into numerical and this particular value into numerical.
Right.
So and then after that take all the numerical value and convert that into standard means.
Scale down that particular value using standard scaler.
That is the reason we have stored this in the form of pickle file.
Okay.
Now uh, let's quickly go ahead and do this.
Uh, first of all, uh, I would like to see just think over it.
Okay?
You, uh, just try to think, like, how do we probably go ahead and apply, uh, one hot encoding
in this?
Okay, now, you really need to think, guys, uh, you cannot, uh, just think over it, okay?
I'll.
I'll give you five minutes.
Just pause the video.
But what task you really need to do?
Okay, this is my new input data I'm actually getting.
And now with respect to this new input data, you need to think, how can I probably take this particular
data and perform a convert categorical features into numerical features?
That is what you really need to think first of all.
The second thing is, uh uh, how do you apply standard scaling?
Right.
And then how do you do the prediction with respect to the model?
Okay.
That is what we are going to probably see.
Okay.
So first of all, uh, pause the video and do it.
Till then I will start copying and pasting the code over here.
The reason is very simple because I have already told you all these things.
Okay.
So here, uh, one hot.
Uh, so let me just go ahead and write this label encoder g0.
So I'll take this label encoder g0 dot transform okay.
And here you'll be able to see that I am getting some values over here like key value pairs.
Right.
Key value pairs over here.
Now when I get this key value pairs I need to take out the information of this particular geography.
So what I will do I will say hey uh uh label underscore underscore encoder dot transform.
And here I'm just going to use my input underscore data okay I think it is input underscore data of
geographic column okay.
And then uh this geography is basically my key.
So let me just go ahead and copy and paste it over here with respect to this.
So I will be able to get my key okay.
And then finally I get the I convert this into an array okay.
Now once you do this again I'll be using this label underscore Geo okay.
Dot get feature names out of geography.
And this is what I mean by geo encoded that I'm actually giving okay.
So if you see this is for my new data that I'm actually able to get this right.
So here it says uh reshape one comma one okay.
Let's see this.
Okay.
Um, here I will just go ahead and use this as like this.
Then it should work.
Okay.
Uh, expected 2D array.
Got one 1D array instead.
Okay, so array of France I have given over here I'm using this transform.
Okay.
Um.
Mhm.
This is okay I have to use one more brackets because that is the uh that is the reason how we got it
right now.
It should work.
So here you can see geography underscore front geography underscore Germany.
Geography underscore Spain.
Guys you may be thinking how did I get to know that I have to use, uh, double brackets.
See over here, if you go ahead and see with respect to the transformation that we did with the help
of, uh, one hot encoding, right?
So here, when we use this one hot encoding here, you can see that, uh, let's see where it is okay.
Uh, here you can see I'm actually giving this one hot encoding over here.
And I'm giving to a list of features, right?
List of features.
And similarly, I also have to give a list of features over here.
That is the reason this is one of my feature over here.
And I'm giving it as a list of features.
Right.
So that is the reason I'm able to get it okay.
So once I do this uh then I will go ahead and combine this entire data, this data with my input data.
So I'll say input data dot reset index drop is equal to true.
Because if I do the reset index I'm actually going to get that uh default index value row index value.
And I'm saying drop drop is equal to true.
And then I'm uh adding this geo underscore uh encoded underscore df okay.
So if I go ahead and see my input data now input data.
See.
So guys uh, here you can actually see that I'm getting this particular error.
Uh, additionally object has no attribute reset index because I just made one simple mistake after this
particular code.
See, the input data right now is in the form of key value pairs, right?
I need to convert this into, uh data frame.
So in order to convert this into a data frame we will go ahead and write PD dot data frame.
And let me quickly go ahead and use this input underscore data.
Okay.
And once I get this this will basically be my input underscore DF.
And let's go ahead and execute this.
So here is my input underscore df.
Um and this is what is my entire row right now.
This row only I have to pass it over there right now for this particular row, what I really need to
do, first of all, I need to do the concatenation, right.
So my this is my input underscore DF.
And I uh, after converting this into my data frame, I should probably, uh, uh, concatenate my geographic
column.
Right.
So I will do that concatenation right now.
Okay.
I have actually changed all the values with respect to the geography column over here.
Right.
So it is basically into two array.
We have actually done this and I've actually got this geo underscore uh encoded underscore df.
Now let's uh quickly encode my categorical variables okay.
Now I will say hey let's take this input underscore df and let's convert first of all this gender because
gender also needs to be replaced with some label encoded value.
So I'm just going to use this label encoder.
Label encoder Uh.
Label encoder.
Underscore gender.
And I'll say hey go ahead and do this transform operation on my input underscore df input underscore
df on which column on the gender column.
So this basically becomes my input underscore df.
So if you go ahead and see my input underscore df.
Now the gender column will either have zeros or one.
So right now it is one right.
So this particular value may be a male.
Before now it has basically got one okay.
So this is perfect.
Till here we are able to get it okay.
Uh I've already done the one hot encoding for geographic column.
So I have this geo underscore encoded underscore df.
Now what I will do is that I will quickly go ahead and do the concatenation.
Now finally let's do the concatenation.
Concatenation Um, with one hot encoded data.
One hot encoded data.
And uh, along with this we also need to add the, uh.
Uh, no need to add the gender data because it is already done.
The changes in input underscore PDF.
Now what we'll do is that whatever encoding we have done for the geography column, right.
We need to append all those columns inside this.
And we need to drop this column.
So here I will just go ahead and quickly write input underscore DF is equal to PD dot concatenation.
Uh let's concatenate our input underscore df.
And from this I'm just going to drop my geographic column.
Same thing.
What we have actually done over there right.
So geographic column and this drop will be done with respect to axis is equal to one.
And here I'm just going to go ahead and write geo underscore underscore uh encoding underscore DF right.
So geo underscore encoded underscore DF is nothing but this particular value which has this one uh,
which has this one hot encoding of this particular feature.
Okay.
That is what we are basically going to do over here.
And uh, I have to also make sure that I put with axis equal to one, otherwise it will become row wise
concatenation instead column wise concatenation.
Now if I go ahead and write input underscore df, you'll be able to see that gender has got converted
from male to one.
And here you'll be also able to see that my three features have got added.
One is geography France, Germany and Spain.
Okay.
Uh, now one more transformation is left.
Uh, that is nothing but scaling the data.
Scaling the input data.
Now, in order to do the scaling part.
So I will be using scaler dot transform.
And here let's go ahead and write input underscore df okay.
So this will basically be my input underscore scale done okay.
Now if you go ahead and see this input underscore scaled I will basically get all the data in the form
of array.
And all these values has basically got scaled.
Okay.
Now finally we need to just predict and see whether the person is going to leave the bank or not.
So I'll go ahead and write prediction.
Uh, in order to do the prediction I'll just go ahead and run model dot predict here, give all the
values over here like input underscore scaled okay.
Get my prediction.
So I will just go ahead and print my prediction quickly.
So here you can see that I'm getting this particular value 0.20.02976.
So and so.
Right.
Um, I can just go ahead and uh get my prediction probability also.
So if I just go ahead and write like this prediction of zero of zero, I'll be able to see that I'm,
I'm, I'm okay right now or let's see this.
I will just go ahead and write prediction scope probability.
So here you'll be able to see 0.297.
It is there I will go ahead and say this particular condition.
If the prediction probability is greater than 0.5 the customer is likely to churn.
Otherwise the customer is not likely to churn.
Okay.
Because this is a binary output.
And I'm just going to keep the binary output with respect to 0.5.
But here I'm actually getting 0.029.
So the customer is not likely to churn.
So in this video entirely right.
How to do the specific prediction?
I've actually done it again.
First of all we have loaded all the pickle files.
Then whenever we get any input data, first of all we converted that into a data frame.
Then we did the one hot encoding of geography.
Then we did label encoding for gender.
Then we combined all those things.
Then we created our entire data frame.
Then we did the scaling right again.
We used the transform feature, then we did the prediction.
Then finally we got the probability.
And then we finally checked whether the person is likely to churn or not.
Right.
So yes, this was it.
Now in my next video, what I'm actually going to do is that I'm going to deploy this entire content
with the help of Streamlit in the Streamlit platform itself.
Right.
So I will see you all in the next video.
Thank you.