‫Welcome back.
‫In the last lecture, we saw how to combine and train our model in this lecture.
‫We will learn how to evaluate performance of our model and how to predict classes on the new dataset
‫using over this train model first to evaluate performance of our model than we have to use the evaluate
‫method.
‫So just write, you have model object name, which in our case is model
‫And then we are calling evaluate method and inside evaluate.
‫We have to give our test datasets.
‫So we are writing X test first the independent test dataset and then dependent test set
‫So let's just run this.
‫So the output here is first the loss and then the accuracy.
‫This is accuracy because this is the metrics which we mention when compiling a lot more than a few remember.
‫While compiling, we mentioned metrics equal to accuracy.
‫And that's why the second value which we are getting here is of accuracy.
‫So on our test set, the accuracy which we are getting is 86 percent, which is really good as compared
‫to logistic liquidations or decision trees on the same dataset.
‫So with those models, you will get around 70 to 80 percent accuracy.
‫But here with ann we are getting 86 percent accuracy.
‫So once again, to check the accuracy score or just to check the performance of your model.
‫You have to use evaluate method
‫.
‫Now let's learn how to predict the probabilities and how to predict the classes on our new unseen data
‫since.
‫Right now we do not have any new data.
‫We just taking first three samples from our test dataset and consider that as your new unseen data now
‫just run this.
‫So we have Stored the first three records from our test dataset and we are considering it as our new record.
‫So there are two parameters which you can predict.
‫First one is the probability of each class and second one is the class.
‫Itself
‫Let's first calculate the probability score assigned to each class.
‫To do that, we can use dot predict method.
‫So we'll write our object name model then dot predict method
‫And as an argument, we are passing our new unseen data.
‫Which is X_new
‫Let's just run this.
‫You can see our new that contains three records.
‫That's why we are getting output for three records.
‫And there are ten values in each of these elements representing the probability values of corresponding
‫class.
‫So for the first record.
‫The maximum probability is for label equal to 10 and the probability value is 0.99 .
‫For the second record, probability is one, for the label corresponding to the third object and for the
‫third record, we have probably equal to hundred for the second object.
‫We are also using round equal to 2 just to round off these probabilities values to 2 decimal digits.
‫.
‫Now with dot predict
‫We are predicting probabilities, but if we want to directly predict the class and not the probability scores,
‫we can use dot predict underscore.
‫Classes method
‫So Syntex is almost same.
‫First, you have to write your model object name and then call the predict underscore classes method.
‫And in bracket, you have to mention your new dataset.
‫Just run this.
‫You can see here we are getting an array of the labels.
‫So for the first object.
‫The class label is nine, so you can also confirm it from here also.
‫The maximum probability was assigned to this object and here also we are getting the position as 9
‫remember the numbering
‫starts from zero
‫So this one is zero.
‫This one is one.
‫And so on.
‫And this one is nine.
‫So for the second record, we are getting the predicted class is 2.
‫And you can also see that the probability was maximum for this record, which is zero one two.
‫So second object for the third record.
‫We are getting the predicted class as one.
‫And in the probabilities also, you can see that the maximum probability correspond to position number
‫one.
‫Now, again, it's a little bit difficult to interpret results like this.
‫Nine to one.
‫So let's just call the label description instead of this, numerical labels. So will do the same thing we did
‫earlier.
‫We have already created a list called class Name.
‫We are just passing y pred into that list.
‫So if you run this instead of this labels, you will get the description of each record.
‫So now let's just confirm this by plotting the image of our first new dataset.
‫So the position is zero and we are using.
‫Iamshow plot this.
‫You can see this photo looks like an ankle boot, and we also predicted ankle boot for the second
‫record where the position is one and see that this is a pullover.
‫And we also predicted pullover.
‫For the third object here, the position is 2
‫You can see that this is a jeans or a trouser and we also predicted trouser
‫So that's how we predict with our model we can use evaluate to evaluate performance of model
‫on test set and to predict new values.
‫We can either use dot predict method or dot predict underscore classes method. Dot predict
‫method will give us the probability values assigned to each class for each record.
‫While predict underscore classes will give us details about the most probable class for that record
‫So that's how we create train and predict using mlp model. now just for a quick summary.
‫We started with importing and installing tensorflow.
‫Then we imported our fashion mnsist dataset with 10 categories.
‫Then we divided that dataset in to train validation and test set
‫And before that we also normalize our dataset
‫Now, after that, we created architecture for a our model this is where you mention the activation
‫functions, number of neurons you want in your layers.
‫After that, we compiled our model to give loss function optimizer and the metrics we want
‫to calculate.
‫And after that we trained our model using dot fit
‫Method
‫And after our model is trained, we can use dot art history method to get all the loss anf accuracy's
‫Values for each epoch.
‫After that, we can use dot elevate method to check accuracy scores on our test dataset, and we can
‫also predict values for new records using dot predict and dot predict underscore classes method.