Transcript for:
Implementing ANN with PyTorch Overview

Hello all, my name is Krishna Iyak and welcome to my YouTube channel. So guys, today in this video, we are going to continue the next session on PyTorch. And as I promised in the previous video that we are going to implement artificial neural network with the help of PyTorch.

This will be an amazing session because here we are going to use a lot of oops concepts, simple classes, you know, you'll be creating an init function. and we will be using PyTorch in actually creating the dense layers on all the hidden layers and such. And this is just a simple example that I'm going to take, guys. In the upcoming examples, I'm going to take complicated examples where we do a lot of feature engineering.

to handle category features and all and then actually create an artificial neural network with the help of pytorch now remember guys whenever you have any questions with respect to pytorch it is better that you go and follow the tutorials on pytorch.org amazing thing they have covered each and everything over here till the deployment you know they have covered everything you just need to explore um you know you need to see how it is basically implemented all the examples all wonderful examples are also given over here but in this video I'm actually going to solve a problem statement, which is related to Pima diabetes We'll try to predict or create an ANN which will Which will basically predict whether the person is having diabetes or not And then I'll also show you how we can actually create the model save the model load the model Create the weights load the weights something like that. We can do a whole lot of thing. So let's go ahead So initially guys to begin with what I'm going to do is that I'm going to import Pandas as PD because I really require this this particular data set the Pima diabetes data set I have actually taken from Kaggle. So if you go over here in the first link you'll be able to get that particular data set. If you are not able to get it guys anyhow I'll be uploading this particular data set in the GitHub repository so you can download it from there.

So initially I'm just going to write pd.read underscore csv. I'm basically going to read that particular diabetes data set. So here it is. this is my diabetes.csv and df.head i'm just going to see now guys initially what i'm going to do is that i am actually going to do some pre-processing create train test almost it is almost similar like how we're doing the machine learning and then probably i'll try to show you how we can create a model with the help of pytorch basically an ann model so to begin with guys the next step that i will do is that i will probably check whether this particular value is DF is having any kind of null so if we don't find any null you can see that no null is actually present what we can do is that we can quickly do one important thing is that probably I really want to see this in a visualized way with the help of seaborn but if I want to really use seaborn suppose if I use import or seaborn as SNS okay I'm going to import this because I want to really see some kind of pair plot and remember guys this kind of warnings will be coming if you execute it once more i think it will not come probably for you all it will not come there is some problem with my jupyter notebook environment so i'm going to use pair plot now inside this particular pair plot i'm going to give my df i just want to see how the data is actually distributed between this diabetes and the person who is not having diabetes so in pair plot you have a hui parameter in this hui parameter i will try to specify my dependent feature always remember guys this is my dependent feature outcome okay and these are all of my independent features that is pregnancy glucose blood pressure skin thickness insulin bmi diabetes prediction function and age with the help of this independent features i'll try to predict whether the person is having diabetes or not so here i'm actually going to take outcome okay and probably the third parameter is not required right now if i execute it guys it will give me an error uh saying that it is not able to understand the outcome variable and this is pretty much true you can see that kde bandwidth is zero the reason why we get this particular error because understand guys this outcome is having ones and zeros okay but usually c-bond you know thinks the outcome as a category feature so it thinks that particular feature in the form of strings so what i can do is that i will just write one condition just to show you this particular c-bond diagram just a kind of data analysis so i will write okay i'll create this outcome and I'll write probably I'll also import numpy so let me import numpy so numpy as NP now inside this what I'll do I'll say NP dot where I'm going to just replace wherever this outcome is 1 is equal to 1 I am going to Place it with diabetic.

I'm just giving a category variable guys. Okay later on They just to seen the seaborn probably you can skip this step if you really don't want to do it I really wanted to show you how This looks in the form of pair plot So I'm just going to execute this and once this is getting executed, now if you go and see my df.head, you will be able to see the outcome which is my dependent feature now has diabetic and non-diabetic. diabetic now when I execute this pair plot again and the hui parameter that I've given is outcome if I execute now it will probably be working fine and we will be able to see all the diagrams because this hui parameter now has got converted into category feature so probably if you're facing this kind of issues this is the way how you can actually fix it I thought initially I used to think that it will take values like ones and zeros also but it was not taking so I had to convert this into diabetic so here is all your data how it is actually distributed just to get some visualization.

But anyhow, I have to get these values as ones and zeros so that I can actually use it. So I'm again going to read this data set. Okay. Again, you can skip this step if you want guys. Not necessary that you need to have that.

Okay. So now my outcome is basically ones and zeros. Now this is pretty much amazing. We have got it.

Now what we are going to do is that guys, first of all, I really want to do a train test split. So I'll write. from sklearn.preprocessing, not preprocessing, sorry, model selection, I'm going to import train test split. So inside this train test split, I will get the values like x train, x test, and y train, y test. Now here I will be basically calling train test split and here I will be giving my x and y and the test size I would like to give somewhere around 0.2 okay and probably random state I can select it as 0 okay now remember one thing guys I did not give x and y where is x and y so x and y I'll be creating from this so I'll write df of dot drop because I in the x I require all my independent feature so I'll write df dot drop and here I will basically write my outcome variable okay when I am using drop make sure that guys instead of this round braces you have to give sorry instead of the square braces you have to give round braces always make sure that otherwise sometimes people get confused with this and then i'm going to say axis is equal to one uh after this i'm also going to convert this into um numpy array so what i'll do is that i'll just copy this everything okay i'll make a new cell so here you have and then i'll just copy this and over here I'm just going to say DF dot no DF of a DF dot DF of outcome.

I can take over here, right? Initially, I dropped it and I'll take it over there. And this also I'll try to convert into numpy values. So I'll just execute this. So X and Y is basically my numpy where X is all my independent features.

So let me just comment it down over here as independent features. Okay, pretty much simple. And this is basically my independent features.

This. This material will be given in the GitHub, guys. You can actually explore it as you want. Now, I've done train test split, the X and Y I've given, and this also will execute perfectly fine.

So, right, I've done it. So, this is the step that is pretty much common with respect to machine learning, right? Now, here actually starts how we will be working with respect to PyTorch. Now, the first step, we will first be creating tensors.

So, I will create tensors. Remember, guys, any queries that you have, just go and explore. explore this. There are a lot of examples that are given.

Like if I take one example with respect to visualizing model data and all. So here you'll be able to see this kind of functions, how they have actually written, how the classes has been defined, everything like this, you also have to use oops concepts. Now the best thing is that whoever loves oops concepts will be able to understand it pretty much quickly.

So first of all, I'll try to create tensors. Always remember all the inputs, let it be the independent features, not the dependent feature, independent or dependent feature, they have to be created as a tensors. So I'm going to first of all say that x underscore train, okay, is equal to torch dot, I have to convert this into a float tensor.

But before I'm using torch, so the one thing that I really want to do is guys, I want to import all the necessary libraries that I'm going to use it. So the first library that I am actually going to use it. These are the libraries from PyTorch.

Okay, libraries from PyTorch. And probably in my previous video, I've shown you how to install PyTorch. You know how we created a new environment.

So in the same environment, I'm actually working. So I'm going to write import torch. The second library that I'm going to use is something like import torch.nn as nn.

Okay, so I'm also going to use this torch.nn. I'll tell you what all these libraries are actually used at. And so you'll also be able to understand.

Then I'm also going to say import.torch.nn. nn.functional as f. Okay, so all these things are actually required. The reason why it is required is that just go over here and you see over here, right, you will see that what is torch.nn really.

So if you don't know about torch.nn, guys, there are some specific design modules inside PyTorch. This torch.nn helps you to create models. Torch.optim actually helps you to create optimizers and then you have data set and data loader to help you to create and train neural networks.

So all these things are there. We'll see one by one and then you will basically enjoy like how I'll be coming up with different different parameters itself. Now once I install it as I told you that all my inputs and my output that is my independent and dependent feature needs to be converted in the form of tensors. Now how to do that that we are actually going to see.

So if I write torch dot float tensor and always remember guys your independent features needs to be converted as a float tensor Always remember that and we had actually seen that also in my previous session. So I'm going to convert this into float tensor Probably my X test also. I'll be trying to convert this into float tensor, right? So float tensor and here I have actually my X test. So both have been converted to a float tensor now Float tensor, what it does, whatever the x value is basically present, will convert that into floating point.

That is compulsory with respect to the independent features. Always remember guys. With respect to the dependent features, it is not that much required.

So I can basically write y train. y train is equal to torch dot. I can use this long tensor for this.

And probably it will not convert that into a... Now if you go and see the definition of long tensor, it will not convert that into a floating point number. So it is not compulsory at all. Because output type is basically my dependent feature.

So I may not have floating point numbers. So then this also for the Y test also I will try to convert this into long tensor. I am going to write each and every code in front of you guys.

So please if possible just try to execute along with me. Okay, so now I have created this. Now is where we will be creating our model from scratch. Creating model with the help of PyTorch. Okay.

So always remember guys, first in order to create model, first of all, we need to define the class. So here the class that I am going to take is ANN underscore model. Suppose I am writing my ANN underscore model like this. And always remember this ANN model will be inheriting.

As I told you, here I have imported the library NN. which is inside torch.nn so i have to basically inherit this nn library which will help me to create the models itself so nn dot i'll write nn dot module so this is what i have to require now inside this guys i will be defining two functions one is underscore underscore init underscore underscore and here i'm actually going to take the self uh then i'll make it pass right now because i want to create two functions and then probably i'll try to pass all the definition And this, the next function that I'm going to create is basically the forward propagation. Okay, so and this will also be taking the self parameter. And let me make this as pass. Now inside init guys, always remember for an artificial neural network, All things are required you require input features you require hidden layers and you require It may be multiple hidden layers and you require output layer now first of all to begin with what is the shape?

What is the shape of df dot shape? Okay, so if If I go and see guys, there are total nine columns. Eight columns are basically the independent feature. We did not have to require any pre-processing over here because all our integer values, right? Only this outcome value is basically my dependent feature.

So what I can do is that I can basically, first of all i'll write okay i require an input feature okay so this is basically my input feature the input feature that i am really going to define over here will be somewhere around you can see that nine features are there right so instead of using nine i'll be using eight because the last feature is the dependent feature so my input feature is this one i'll say hidden one the hidden first layer probably i'll take it as uh 20 nodes 20 hidden nodes right then this is hidden 2 i'll also take this as 20 hidden nodes okay and probably my output layer so my output or output features i'll say how many output i basically want it is either zero and one so i'm going to take it as two i'm going to use cross category cross entropy guys for this i'm just not using binary cross entropy because i really want to show you how the probability values will be coming up so this is what is my whole ann design now see in the input features the eight feature the hidden one layer is 20 the hidden two is 20 hidden neurons then the output features is two. I'll just remove this pass because I don't require it and then I will initialize. First of all, I have to basically inherit the parent class that is nn underscore module. So I'll write like this and then, sorry, should not be defined like this.

Okay, super dot underscore underscore init underscore underscore with that brackets and then I'll go to write self dot fully connected layer one and then I'll just write like this. Okay, I'll write I'll create this kind of variables. So this is my fully connected layer now in order to create a dense layer Always remember guys first hidden layer I'm having eight input features that input features is going to my hidden one layer, which is having 20 hidden nodes So this to this is basically a fully connected layer in order to create a fully connected layer I just have to create a dense layer right what is saying Keras in order to create dense layer over here? I'll just use an end dot Linear okay linear and this will basically take the parameters as input which is my input underscore feature right comma hidden one so this is what right I'm connecting my input layer to the hidden one so for this two parameters is required in my first connected layer then in my second connected rare F underscore connected to right I'm again going to take my linear which is basic just like a dense layer and over here I'm going to take hidden one to hidden 2 so this will now be connected see from input to hidden 1 now hidden 1 to hidden 2 so I'm going to take this as my hidden 2 and finally I will get my outcome layer which is nothing but an n dot linear right and now this hidden 2 will be connected to out underscore features right this is basically my output value right this output features right so this is how my whole network looks like it has one fully connected layer which is which is basically connecting from the input to the hidden then hidden to hidden one to hidden two then i have hidden to the output features sorry this should be hidden too right this should be hidden too now uh similarly this is with respect to my init function what about my forward propagation now forward propagation how i will create is that i'll create a variable and inside this there will be another variable which is like x okay which will track the gradient descent and all the back propagation so this will basically over here you can see guys inside this functionality right i have taken this torch.nn.functional f now inside this f you have all the activation function like relu sigmoid and all so here i'm actually going to apply relu so relu is basically getting applied in self.the connected layer of f1 okay so connected layer of f1 and again after this what i'm going to do i'm again going to write f.relu on cell self.fConnected2, okay?

And remember, guys, this fConnected1 and fConnected2 will be having this parameter x, which is just all the information that we are creating with respect to that particular layer. And finally, you'll be able to see that... self.out will be given to with this particular x value, right? And finally, I'm going to return x. So this is how the forward propagation is basically happening in the forward propagation.

I'm just applying ReLU activation function on the fully connected. connected layer one and two and whatever output I'm actually getting I'm just giving it back and I'm returning it back so this is what is about my class now pretty much simple guys if you know oops concepts if you know the terminologies in ANN if you can also check my deep learning playlist there everything is giving now what I'll do is that I will instantiate instantiate my ANN underscore model now I really need to start working on it so I'm going to instantiate but before instance I will also set a seed so that my initial weights gets applied. So here in the seed, I'm just going to take some manual seed value.

You can also use, if you are taking the same value like mine, then the same parameters will get assigned. After this, I'm just going to say model, ANN model, I'm going to just initialize this. So if I execute it, I'm getting some error. Object needs an argument.

Let's see. Oh, this is probably a little bit. Oh, okay.

One problem that I did is guys, I did not make this bracket. So if I make this bracket, so it will then basically inherit from the nn.model. So once I execute it, now you can see that I'm getting executed. Now, if I write model.parameters, here you'll be able to see your whole information like how we see in Keras, like writing model.summary.

So here you can see the input features are 8, output features 20, bias 2 with respect to the fully connected layer 1, fully connected layer 2 And finally I'm getting my output feature as 2, right? So these are my model parameters. Now remember guys, this is here what I've defined is basically my init and my forward propagation, right?

Now always remember once the forward propagation basically gets over the next thing that we do is basically about the backward propagation. Now in order to do the backward propagation we have to define the If I write backward propagation, backward propagation, in backward propagation we have to define the loss function, okay, loss function and then we also need to define, we also need to define the optimizer because loss function when it is created, loss function is nothing but we are comparing the predicted value and the y value, whatever difference is coming, we have to reduce that difference and that difference will be reduced with the help of optimizers. So for doing the backward propagation, what we are actually going to do is that we are first of all going to create the loss function.

So loss function is a variable that I've actually created. And again, I'm going to use nn dot. If you go and see guys, there are a lot of functionalities and probably I'll be using all this when I'm doing my CNN. But with respect to loss function, you can see that there will be something like C over here. Let's see.

Okay, there is something like cross entropy, I guess. So cross entropy loss. So I'm going to use this cross entropy loss.

Just understand, whenever you have multi classification problem, you can use this cross entropy loss, okay, for this. And then next I will be initializing the optimizer. In the optimizer, I'm just going to use torch.optim which we saw in the page. And inside this optim, sorry, inside this optim we have something called as Adam, AdaDelta, AdamX, AdamW. I'm going to use Adam.

Because Adam is very much good and here I'm actually going to provide all the parameters of my model that is this is all values Okay, and then once I provide the model parameters You can also see that this model parameters are basically generators, right? So this is like generator and this generator, you know that all the parameters one by one one by one layer It can actually retrieve it. So I'm just going to remove this bracket and show you so like this one by one layer Can we actually passed? And the second parameter inside the atom is basically about the learning rate and here I'm actually going to initialize the learning rate as 0.01 Again, the learning rate should not be a very very small value or not a very very high value Otherwise, you know, we'll never be able to find out the global minimum So finally we have done this and I'll execute this so I have defined my loss function I have defined my optimizer. My model is ready my optimizer now I have to basically trigger it, you know trigger the forward propagation automatically everything will start So first of all, I'm going to define the epochs as 500. Suppose I want to run for the epochs of 500, and I will be creating a variable which is called as final losses.

So here I will actually store all my losses value, okay? Now I will say for i in range of epochs, I'm basically going to run for this many number of epochs. And when I'm running for this many number of epochs, what I'm going to do, I'm also going to increment i is equal to i plus one after every epoch.

we will basically be incrementing and then I'm going to find y pred y pred if I want to find out I just write need to write y dot forward model dot forward and this forward is basically this particular method you know where we are actually providing this now this forward requires one x value now what is this particular x value that we have to give is basically my x underscore train right so this x train we will be providing after the y model forward is actually running then we will go and compute the loss and the loss is basically computed by using the loss function which we defined over here right loss function of this particular value and this loss function inside this i have to give the parameter as y pred and y underscore train because this is what we actually trying to compare okay you can give y train comma y thread or y pred comma y trends one and the same after this what we are actually going to do is that guys i am going to append this loss inside this final losses, okay? So that every time I will be able to track it down. Now what I'm going to do over here, I'll just write a condition.

I'll say that if I percentile 10 is equal to one, okay? So I'm just basically saying that for every 10 epochs, print something, okay? So here I'm actually going to print something like this.

Okay, I'm going to write epoch number, okay? Is this this? or let me just write it with colon and the loss is and the loss is like this dot format i'm going to use dot format and here i'm actually going to provide my epoch number that is i comma loss is basically present in the loss variable itself so and always remember this loss will be having something like dot item okay so where it will be showing you what is the loss value just by using loss you won't be able to see it will be in the form of key that additional repair okay now once we have done this the last step we have calculated the loss now we need to reduce the loss now in order to reduce the lost I have created something called as optimizer inside this particular optimizer we will be using a function which is called as zero grad now this zero grad is nothing but it says that clears all the gradients of all optimized class so after every epochs it creates the gradients of all the optimized class and this is pretty much required when we have to do the back propagation. Now once this is done we are going to use loss.backward.

Loss.backward is basically to back propagate to find out the derivative which we have seen in our previous class and finally you'll be also being able to see this and then finally what we'll do is that we will just write optimizer.step okay. So optimizer steps it performs a single optimization step that is what it says and this backward is basically for the Back propagation now guys. I will be running this for 500 epochs and probably we will be seeing that whether the loss is Decreasing or increasing.

Okay, so for I in range, sorry for that fine range Yes Now if I execute it now you can see that it is quickly running and it is run till 500 epochs and here you can see that From 3.45 it has been reduced till 0.35, right? Now the next thing that I really want to do is basically plot the loss function. So plotting the loss function over here, plot the loss function. Now in order to plot the loss function, what I'll do is guys, I will just import matplotlib.pyplot as plt, okay?

And then I'm going to use percentile matplotlib. matplotlib.pypod as plt, right? Now, once I execute this, guys, probably...

Oh, sorry. What I have written? I should write matplotlib inline.

Okay, fine. Sorry for that. So, once we have done this, I'm just going to quickly plt.plot.

I'm going to plot all the epochs that I've actually defined, like basically 500 epochs, right, to see... whether the loss is decreasing or not and my final underscore losses right that is the variable that is the list i've created where i'm storing all the losses then finally i'll write plot dot y label is basically my loss right and then plot dot x label is my epoch so once i see this guys here you can see that the loss is increased decreasing like this and usually the loss is decreasing from the first iteration itself and we are actually getting Like this kind of diagram, which is pretty much okay and pretty much good enough, right? We usually require in this particular format now guys, how do we do the prediction that is first of all required that?

How do I find out what is the prediction or whether our prediction is correct or not and everything as such now? We will try to do the prediction on the X test data. So let's see So prediction in X underscore test data, and then we'll also try to draw our confusion matrix. So here I have predictions, okay?

Now inside this prediction, I'm just going to use for I comma data in enumerate. Inside this enumerate, I'm just going to give my X test. Enumerate will actually help me to iterate all through all the X test data.

In order to do the prediction guys, I just have to use like model and I have to give my data like this. Okay So once I do this, you'll be able to see my output. Okay, this output model is basically whatever model we want to predict and a model that we have actually created. You can see over here this model that we have actually created and we are going to use that same model and just give that data inside this.

Okay, once I execute this guys, you can see that I'm getting I'm getting something like these all values. Okay, one issue that I also see guys over here, you can see this gradient function like this, right? Probably you can also prevent this gradient function by using something like this.

Okay, so what I'll do is that I'll just say With with torch dot no underscore grad Okay, this is required because now when we are actually evaluating the results, we don't require gradients, right? So we have to basically write with torch dot no underscore grad At that time you will be seeing that this gradient will not be coming up. Okay now and that is actually not required guys because Gradient is only required the back propagation part is only required when you are training your model during this particular scenario You don't require it now here.

You can see that guys I have enumerated through X test data, and I have given that particular value inside my model Model inside this bracket. I've just given data, so I'm getting two outputs, which is basically what I wanted right, but still this Index we need to get whether it is 1 or whether it is 0 that particular index value We need to get now in order to get that particular value What I'll do is that I'll say model dot data model of data and then we can actually write I'll just try to save this in some variable for the easiness So I'll write y underscore bread now after I write y underscore bread one thing that I really Can do is that I can also print? I can also print y underscore pred, okay?

Dot, there is a function which is called as argmax, which will help me to find out which index maximum it is. And then if I use dot item, I'll be able to see whether the index is zero or one. One basically says that the person is having diabetes.

Zero basically says that the person is not having diabetes. So finally, you'll be able to see this kind of output, right? This kind of output.

Now one more thing that I will do is that guys I will just try to append inside this predictions. Okay so predictions.append I'm going to just append this whole value inside it. Okay so this predictions will basically have my list of values like that. So finally if I go and see my predictions you'll be able to see that it is a list of one zeros and this right.

Now I have my predictions I need to compare it with my new with my X test data. So for comparing with my X test data, what I can do is that I can use something called as confusion matrix. So from sklearn.metrics, I am going to import, I think confusion matrix is present over here.

Yes. So I'm going to say cm of confusion matrix and here I am actually going to give my y underscore test, comma predictions, which is in the form of list. So if I go and see my cm, And this is basically my output. You can see that 90 right results, 32 right results, 17 and 15 are my wrong results. If you really want to see it in a better format, you can also use some heat map figure.

So here I'll be defining plot.figure and basically my fix size is equal to 10,6. I'm going to use this fix size. And after that, I'm going to use snh.heatmap. Inside this I'm going to use cm and anode is equal to true.

I hope this is pretty much simple for all of you, right? I think it should not be a much problem because this is the basic thing in plotting and probably if you don't know it just go and check my playlist there I've actually defined everything so in the X label I'm going to say predicted value sorry did I get predicted no this in my X label it should be my actual value okay and actual values and in my Y label y label i am actually going to give my predicted values okay so if i execute this guys okay i'm getting exactly okay figure size so this usually happens when you don't type when you type it in very fast manner so finally you'll be able to see guys over here uh the actual values okay sorry the x label should be the predicted or actual i think it is fine so here it is with respect to this i'm getting this this is my true positive, true negative, false positive and false negative. All these values are there.

If I really want to find out the accuracy, so I can write from sklearn.metrics import accuracy score and then I can say score is equal to accuracy score and here I can actually give my y test comma predictions. Okay so finally if I go and see my score it is somewhere around 79 percent. which is okay because here you can see that it can still decrease.

You know, this loss can still decrease. I can still continue the loss. Now, this is how I have actually created.

Now, one last and the most important things. Okay, I feel that yes, this model is perfectly fine. Now, I really need to save this particular model. So, in order to save the model, guys, save the model, what should I do?

So, in order to save the model, there are multiple ways to save it. First way is directly to save the whole model. So I can write torch dot save and here I will be giving my whole model and finally I will be giving Something like diabetes dot PT and always remember the extension of saving a pie torch model is dot PT. So once I execute it It will be giving this kind of warnings, but it is fine Okay So if I go and see file and open here You'll be able to see that diabetes dot PT seconds ago six point five K K B, right? so after this if I really want to upload this particular model right how do i upload it so for that i can create the variable same model is equal to torch dot there is a function which is called as load right and here i'm actually going to give my diabetes dot pt remember guys here i have given my local for local folder path okay if i don't give any path as such so here you can actually see this and once i execute it and after this if i write model dot eval and c you'll be able to see that same you connected layer same ann model is basically present over here right so this is how i have actually done now this is with respect to save and load okay this is with respect to save and load save and load the model okay now one important thing one more important thing that i want to say is that how do we do the prediction of new data point okay prediction of new data point okay So what in order to do the prediction of new data point guys, what I can actually do is that I will just create one tensor list.

OK, if you if you want instead, first of all, let me do one thing. Let me just take DF dot I lock. OK, and suppose I just want the first record.

OK, so first record like this colon minus one. I don't want all the columns because the last column is basically the output column. Right. So I will just try to. convert this into a list.

I just want to get this list format so that I can copy and I can actually create a list one. Okay, like this. I will try to change some of the values like this. So 130, suppose I want to change this as 25. I want to change this as 40. I want to change this as 45. Okay, so this is basically the list that I have created.

So, this is my new data okay suppose this is my new data new data okay so this is my new data now first step I have to actually again convert this back into torch dot tensor okay I can use torch dot tensor torch dot float tensor because it is anyhow in decimal points right so here I'm actually going to give my list one Okay, so list lsd1, okay, and finally I'll just write it this as my new underscore data So this new data, I am actually going to use it now If I really want to find out what will be the output of this I will just be using the same methodology whatever I used over here on the top where it is yes over here I'm just going to copy this with torch dot no underscore grad because again we don't require over here I'm just going to write predict new data, right? Using PyTorch. Now here you can see that I am just going to give this, at least I don't require enumerate also.

I'll just remove this, okay? I don't require because it is just one single value. So I'm going to say print model of the new underscore data since I just have one data. And if you see that this is what it is. is the output but I really want to see the index again what I'll do is that I'll just copy this whole thing and again I'll be using dot arg max right so I'm just going to use dot arg max dot item right and if I go and use this now you can see that the my output is one so with this particular values the person is going to face is basically detected as diabetes okay so this is what was about this particular video I've shown you how to do each and every everything just follow this particular steps now here we did not do much more feature engineering guys but we found out a very very easy way how to create it the theoretical knowledge of anm is pretty much important okay and based on that this whole thing is actually being able to get it right and i have shown you how to save the model how to load the model and how to create for the new test data how do i do the prediction so everything is basically shown so i hope you like this particular video this was all about this particular video guys please do subscribe the channel if you have not already subscribed we are pretty much near to 200k and yes in my next video i'll be coming up with much more complex problem statement with respect to an and i'll try to solve it in front of you so yes all this particular information will be given in the github that is given in the description of this particular video so thank you one doll have a great day bye