‫In the last lecture, we have created the structure for our multi level Perceptron model.
‫Now, before training this model, we need to set up the learning processes.
‫And to do that, we will use the compile method.
‫We will first give the lost function.
‫Then we will give the optimizer.
‫And then the metrics we want to calculate to judge the performance of our model we are using.
‫Loss function as sparse, categorical cross entropy
‫We are using this because our y data is available in the form of labels in our data.
‫We have specific labels for ten different items and that's why we are using this sparse categorical
‫Cross entropy
‫If instant we had probabilities per class in our Y variable, then we had to use Categorical
‫Cross entropy
‫But since we have labels, we are using the sparse, categorical Cross entropy.
‫And suppose we had binary labels such as yes or no or true or false.
‫In that case, we had to use Binary Cross entropy.
‫You can get details of all these loss functions in the official keras documentation.
‫I have provided the link of that documentation.
‫So if you open it, you will get details of all the parameters that this compile method can take.
‫You can look at all other optimizers and lost function and metricses in the following documentation's.
‫Then for optimizer, we are using sgd, sgd simply stands for stochastic gradient descent.
‫In other words, we are just telling keras to perform back propagation algorithm and for metrics, we are
‫using accuracy since we are building a classifier.
‫We have to use accuracy.
‫If you are using the regression model, you can use mean square error and so on.
‫So basically, we have to provide this information before fitting our training data.
‫So just run this command, we are giving three parameters
‫Compiling.
‫Snow, we have compiled our model. Next step, is to fit x train and y train data in this model.
‫This is the syntax of fitting the model we are calling dot fit method.
‫And then we are providing x train y train, the number of epochs.
‫I hope you remember what epochs are we have discussed in our theory lectures and by default the epochs value
‫is set to one.
‫So if you don't mention epoch, by default, the value is one.
‫And then since we have validation data as well
‫So we are providing X valid and y valid datasets that we have created in our previous lectures.
‫We are storing this object into an another object, which we are calling it model history.
‫So let's run this.
‫You can see at each epoch during the trianing, keras display the number of instances process.
‫So far.
‫You can see there is a progress bar and we are getting information of each epochs.
‫And then we are also getting the loss, accuracy, validation, loss and validation accuracy during
‫each epoch.
‫So it will take some time depending on your system configurations.
‫So I'm just fast forwarding this.
‫Now the training is complete.
‫You can see that the loss on our training data is zero point zero eight accuracy is zero point nine
‫seven for our validation set loss is zero point three nine and accuracy is zero point eight eight.
‫So if you food just compared with the first epoch
‫Value the accuracy on our validation set during our first epoch was zero point eight nine.
‫Now you can see our validation, accuracy is oscillating but our training accuracy.
‫So during the first epoch, the accuracy score was four nine five two.
‫And after the last epoch the accuracy score is zero point nine seven.
‫So in each epoch, the training accuracy is increasing little by little.
‫So now we have trained our data
‫There are few more parameters that are available with fit method.
‫One important parameter is class weights.
‫So if you have some uneven distribution of your classes in youe y variable.
‫So suppose all over 60000 reports, 50000 were shirts and rest if
‫Nine categories are spread across the remaining 10000 records.
‫Then we have to use class weights to give larger weight to underrepresented classes and to give lower weights
‫to over represened classes.
‫since in our dataset the categories are uniformly spread and there is no uneven distribution
‫of categories.
‫That's why we are not using class weights.
‫But if in your example, there is some under representations of some specific classes, then you have
‫to use class weights after fitting your model you can call different attributes of our model
‫than history object.
‫So you can call parameters.
‫This will give you information of all the parameters that we have use in training this model.
‫We have another parameter that is dot epoch that will give you details of each epoch and the most important
‫attribute is history.
‫So if you write your object name.
‫And then write dot history.
‫This will give you all the loss accuracy, validation loss and validation accuracy in the form of
‫dictionary.
‫So this is the lost value on our training set for the thirty epochs
‫Then we have the accuracy value on our training set for the thirty epochs
‫Then we have the validation loss of our thirty epochs
‫And lastly, the validation accuracy for thirty epochs
‫So all the information which you were getting while training your data.
‫You can also access that information by using stree attribute.
‫You can also plot this information to visualize how our accuracy scores are changing with each epoch.
‫So here I am just plotting model history history.
‫The information that we have here.
‫And then we want the grids in our plot.
‫And then we want our Y-axis to be between 0 and 1. If you plot this
‫You will get a graph of this kind on top.
‫We have an orange line of training accuracy.
‫Then we have a red line of validation accuracy.
‫Then we have a green line of validation loss and then a blue line of training loss.
‫If you can see with each epoch the training, accuracy and the valuation, accuracy is increasing and
‫the loss is decreasing.
‫You can also tell that the model has not converge yet as the validation accuracy is still going up and
‫the validation loss is still going low.
‫So for our next try, we should run it for some more epochs.
‫And if you call the fit method again.
‫Keras will continue to train this model where you left off.
‫So that's why if you just run this code again.
‫The kera will train this model for 30 more epochs and you will get graph from here.
‫So try running it for 30 more epochs in the next video.
‫We will learn how to predict values using this model.
‫Thank you.