Hi, guys.
Welcome to this session on modeling, in which we are going to build our own model which permits us
pass in these kinds of inputs and it tells us whether the input is that of a person will sign angry
or happy in the session.
We are going to start with the LINET model, which we saw in the previous session while modifying some
parameters to suit the problem we're trying to solve and then move on to even more complex and better
computer vision models.
We copy the code from the previous session and pace out here.
So there is it.
We have this little net model which we saw in the previous example, and then we also have this finalize
this number of classes here which we have to set.
So that set your we change this number of classes from 1 to 3.
Now, the reason why we're doing this is simply because in the previous session we were building the
net model, which takes an images and outputs.
Whether these images are those of a parasitic or a known parasitic cell.
Now, in this example, we're taking an images and our model has to decide whether is that of an angry
person, a sad person or a happy person.
So we see that here.
We have three different classes, and because of that, we're going to change this to from 1 to 3.
So we have this.
We run the cell.
That's fine.
We also have this other configurations, the learning rate, number of epochs, the dropout rate, the
regularization rate, number of filters, canal size, number of strikes, pool size, number of layers,
or rather outputs in this dense layer and a number of outputs in this other dense layer.
So with that, we're just going to run the cell.
Now, note that you could always get back to the previous sessions to understand each and every parameter
we have here as we've discussed this already.
So we just seem to replicate in this little net model we've seen previously.
Now, that said, you see the kind of output we get here.
We have 6 million parameters.
We have our different layers going from our Conv layers to our fully connected layers.
Now the next point here is this activation right here.
So this activation now with a previous case study was the sigmoid.
And this was because we're actually deciding whether an output will be one class or the other.
It was a binary classification problem wherein we could use this kind of sigmoid activation function
with the sigmoid activation function.
If you can recall, we have this input and we have this output.
So let's say X gets in and Y goes out and here's 00.5.
Yeah, we have this and one.
So what goes on here is as we take in higher values of X, the sigmoid function approaches one, while
as we take in high negative values of X, the sigmoid function approaches zero.
And so the range of values here is simply 0 to 1.
And this is logical since in the binary classification kind of setting, we wanted to output a zero
for one class or a one for another class.
Now intermediate values like 0.7 will be taken to be either one of these classes, depending on our
threshold.
But then the role of the sigmoid here is to make sure that all our values, that's based on all the
inputs, we are able to have an output which always lies between zero and one as we could see.
You see that we always in this range here, 0 to 1.
Now, in a case where we're having a multiclass problem, like in this case where we have three different
classes like this and that, what we don't want is to just say, for example, here we have an output
0.1 output 0.67 output say one.
So we do not want this kind of outputs right here since we're dealing with a multi class problem with
single level, since here our output cannot be two of those classes.
So in some problems or in some kind of problems, we may have a situation where the person is maybe
sad and say angry at the same time.
Now in those kinds of situations, you could afford to have this kind.
Kinds of outputs where, say, these two year, these two classes have high values nonetheless.
And the kind of problem we're trying to solve, we want the model to choose or pick only one out of
the three different classes.
So we're not going to pick two or one.
We're going to pick only one.
And because we're going to pick only one, what we have here, what we try to do here is to make sure
that this our output sums up to one.
So instead of having let's take this off, instead of having this kind of output, we'll have an output
which sums up to one such that this year if you have that such that one, the one with the highest class
or the one with the highest value is considered as that class which the model has selected.
And so we could have different kinds of values.
We could have say 0.1 year 0.2.
But here, since we already have 0.10.2, we're going to have 0.7.
Since we want to ensure that the sum of all these values should give us one, we look at this 0.3 plus
0.7 gives one.
So we make sure that our values here lie between zero and one.
And when we sum them up, it gives us one.
Now, an activation function, which we could use in achieving this, is the soft max function.
So let's have here soft max.
So instead of the sigmoid, now we have the soft max.
And to better understand how the soft max works.
So you clearly see that difference.
Let's take this example from the analytics Viacom website.
In this example, they are considering that we have three classes in this output.
Let's take this off here instead of ten like what we have now here they have just this three classes
right here.
Now, after applying the soft max, we're going to have outputs here, just like when you have some
output.
After applying the sigmoid, you have this other output.
So just like, for example, if you have an output, let's say five, after applying the sigma of five,
you have a value like 0.9, nine, whatever.
So it's a very, very close to one.
Whereas if you pass in a value, say negative ten after passing in the sigmoid, you're going to have
a value very close to 0c0 .001 So this is how the sigmoid works.
Now for the soft max function is quite different here.
What goes on is we're going to make use of this formula here.
So we have x, let's say x I, or let's say X for a particular class divided by the sum of e, x c for
all the classes.
Now, this formula shouldn't scare you as we're going to explain how it works in detail here.
That's that we have in this input.
Just like with the sigmoid where you have the the input coming from the output of the dense layer.
Now here we have this year we have obviously three inputs because we have three different classes.
So we have this one, this one and this one.
Now you should note the values here.
Let's take this off so you can see the value here.
So you know the values.
This one is 2.33 -1.46 0.56.
Now, once we have this, we're going to simply apply this formula and the weights apply this as such,
you take this value 2.33, we have the exponential of that value.
So you have e to the power of 2.33 as you see here of that particular class divided by the sum of all
these exponentials for all the different classes.
So you have each step of 2.33 there is it divided by each step of 2.33 plus here E to the power of negative
four, 1.46 plus each of 0.56.
So you have all this summed up.
That's basically what this formula here means for all the different classes.
Sum up E to the power of the values that is, classes take up.
Now, once you have that for this first class, class one, you obtain this value.
Now for the next class you have e to the power of -1.46 divided by this same some years.
So basically this sum is the same everywhere, but the only difference is the numerator.
So you have this numerator which changes.
Here we have 0.56, we have this other numerator and we have this value.
Notice how as the value goes towards negative high negative values, these values are put in zero,
while when the value is going towards a high, positive value is approaching one.
So this means that if we replace this and put a value.
Exit ten would have a value even very close to one like, say, 0.9.
So that's it.
And that's basically how the soft max works.
So this means that at every given point when you sum up all these outputs, you have a total value equal
one.
So you could take the 0.83 plus 0.01 less 0.84.
Let's walk into decimal places.
So 0.840.84 plus 0.14 is like 0.98.
So you add this other parts up to give you one.
So basically what you're doing with the soft max is you're taking some inputs for, let's say, three
classes and then you sharing the values.
So you have one that you want to share.
You have this number one which you want to share.
You're going to give this one fraction of this whole one.
In this case, the fraction is 0.83.
And then you're going to give this other one's own fraction, this other one, its own fraction, such
that at the end, all this year, sum ought to be equal one.
From here, we're going to get straight into the training and start by designing our loss function.
So we have this last function which is going to be the categorical cross entropy function.
So unlike before, where we had the binary, now we have this categorical cross entropy, we have it
under documentation.
You have to cross losses, categorical cross entropy.
And then one of the arguments is this from logics now from logic, as given your Oh, let's get back
here.
The from logic by default is false.
So by default we suppose that we have from logic to be false.
And as given your this from logic says whether the y pred the y part is what the the other y which is
outputted by the model.
So this is whether the y pred is expected to be a logic tensor or not, and by default we assume that
y pred encodes a probability distribution.
So by default we are supposing that what the model is going to output.
In our case we have three classes.
What the model is going to output is going to be such that when we some others probabilities about some
others outputs here is going to give us a value of one.
And so when we have this by default, that's from logit to be false.
So by default we have from largest to be false when we have this is simply meaning that we're supposing
that what is going to get into this last function is going to be a larger tensor.
And that's our case here because we've had or we have this self max activation.
Now in case we didn't have this solve my activation, then we'll have needed to specify this or set
this to true such that what gets into the categorical cross entropy is a largest tensor.
Now that said, let's go ahead and test this example.
Here we have this example.
Let's take this example, copy this and then just paste it out here.
So we have this example.
There we go.
Yeah, we have this categorical cross entropy.
We're going to print this results.
So we print out the results and see what it gives us.
We run that and you see we have a value of 1.17.
Now this value here tells us how close the models prediction is to the true values of y.
Now let's modify our model's predictions such that it's very close to the true values of y.
So yeah, we have zero maturity.
0.050.950000.100.8.
Now we should reduce this to 0.08.
So the very close to zero now.
Yeah.
Instead of 0.1, let's say we have zero point.
Now let's, let's change this 0.05 and then here we have 0.85.
So all this sums to one, this to sums to one.
That's it.
You see, they are very close now.
Now with this we run the cell again.
And what you notice, you see the value drops by almost a factor of ten.
So this shows us that these two are very close to each other.
Now, let's change this and say 0.0, Let's have here 1.0 and you're zero zero, your 1.0.
We run that and what do we get?
You see, you have a value which is practically zero.
And this is because these two values are very close.
Now, if you change this again, so let's have here zero and have this 1.0, let's now make these values
completely different from each other.
So here we have 1.0 and that so this means that this year the actual.
Position is this position your while, this one or what?
The mother.
This is a different position now you're the actual is this but the model predicts this.
So the model fails to predict for each case here.
So your let's run this again and see how high this value is.
So this shows us how this categorical cross entropy loss actually works.
Now, to gain even more in depth understanding of how this works, let's consider this foreign formula.
So this is the categorical cross entropy loss defined here is simply we have this negative.
Here's the sum of y true log widespread.
Now we take this example here for this case, or let's modify this such that this first prediction here
matches this prediction and or rather this second prediction matches this second prediction and this
year doesn't match.
So this example, let's yeah, this doesn't match.
So the first example doesn't match while this other example matches.
So what the model predicts matches what the model was meant to predict.
Now, that said, let's get into this formula and see how it works so we understand why we get in high
values when there is no matching and very low values when there is a match.
So here, for example, we have zero this y true, just use the formula zero then log of 0.01.
Now we have the summation.
So plus this next example one this is y true one log of 0.05.
You have that plus next one zero log of 0.96.
Now, obviously this cancels because we have zero year here too.
We have zero.
This goes away.
We left only with this.
Let's take this off.
So we left only with this year after this computation.
Okay.
Now log of 0.05 gives us -1.3, approximately -1.3.
So we have here approximately -1.3.
But what is negative here gives us 1.3.
So we have this value of 1.3.
Now let's try example here for this case where there is a matching, we have zero log of 0.1 because
we have zero is not going to be considered here.
We have zero again.
Zero here is going to multiply.
That is going to be zero.
Now, this other one, we have one.
So that's what I want.
We have one log of 0.71 log of 0.7.
What do we have here?
This gives us -0.15, so we have approximately 0.15.
So we see that with where there is a matching, the loss is reduced and when there is no matching,
the loss value is increased.
So we that we just simply take this off since it's our default and that's fine.
So we have this now.
Before continuing, let's also consider a case where our outputs like let's get back here, we're going
to run this again, get the loss we have.
So now we're going to consider that this Y true, that's our data set is going to be designed such that
instead of having this category called kind of output, we're going to have the integers.
So here instead of 010, we're going to simply have one.
Now, let's get back to why this is so.
We have 010.
This is translated that's this for categorical and for integer.
This is translated as one because the one is at the first position.
We're starting from 012.
Now, in the case where we have 001, this is translated as two since this are the second position,
0012.
So that's it.
So we had seen this already in the previous session.
Now getting back here, let's modify this.
Instead of having this, let's put one.
And instead of having this, let's put two.
So we're saying that if your data set is designed in this way, recall we have seen it here, just here.
Let's get into dataset loading just here.
If the level mode is int, then you should have this kind of design that we go right here.
Okay, so we have this kind of design instead.
So we just have this integers.
So if you have this, let's run this here, you see, doesn't work.
Now what we would do in the case where we have this kind of output is we're going to use a sparse categorical.
So instead of the categorical we have the sparse categorical.
You see you run that and you have the exact same answer you will have in the case where it was categorical,
Let's get back here, run that again.
So you have the exact same answer.
So that said, we could make use of the sparse categorical.
It depends on how we created our dataset.
So here we have sparse, categorical and we should just into this since we're not making use of that.
Let's take this off now and then we move on to our metrics.
So here we have the metrics.
The metrics we're using here will be the categorical accuracy.
So we have categorical accuracy.
Let's give it a name, let's call that accuracy, and then we will also have the top K accuracy.
There we go.
We have our top K categorical accuracy.
We'll give it a name before giving it a name, you need to give it the value of K.
So we'll call, we'll give a value of K of two and then we give it a name top K accuracy.
Now before we move on, let's explain this top K categorical accuracy metric right here.
So unlike with this accuracy, with this categorical accuracy, where if we have, for example, this
for situations here, there's four examples.
This those in blue are what the model predicts, and those in red are what the model was expected to
predict.
Our accuracy will be computed as such.
So we'll have we'll start with this first one.
The highest year is this 0.5.
The highest year is this.
Since there is no match, we have a zero plus.
We move to this next one.
The highest year is this.
The highest is the highest here Is this and the highest is this.
At this position there is no matching.
So we have a zero and that's because the class zero was picked, whereas the expected what should have
been class one.
Now we get your the class zero is predicted by the model and the class zero is also what the model,
what was expected or what the actual outputs.
So here we have plus a one because we've gotten this correctly.
So this is correct, this is wrong.
This is wrong.
Now we get your we have the same situation.
The highest here is 0.7.
The highest here is this.
And the position in is such that there is a match.
So we have plus one now because we have four different examples.
We divide all this by four and multiply by 100.
So this gives us accuracy of 50%.
Now we get back to this case here for the Typekit categorical accuracy.
For this first case, the highest class here is this one, the second highest.
US is this order one year.
So we have this highest class second and we have this third.
So in this order for this one year, this our first.
We have two of them.
And then this one.
This is our first and this.
This is 0.05.
So yeah, we have two of them this year.
This is our first and this our second.
So because we've selected K equal to we interested in just our first two highest predictions.
So with the top K categorical accuracy, we are not interested in making sure that the highest prediction
here matches the highest prediction.
Here's what we're interested in here is if any of the two highest matches the highest prediction we
expect.
So if any of the two predictions of the model matches the exact prediction in the model should have
predicted, then we will give that or we consider that as a correct prediction.
So this case here, these first two do not match this.
So this is a wrong prediction and we have a zero plus we move to this next one year or the highest year
is this and it matches with the second.
So we have a one.
So this is considered now correct prediction unlike previously where we would have considered this to
be a wrong prediction.
Now for this one, the first two of the three there.
So obviously this would be a right prediction.
It also matches here the first matches with this first year.
So we have that plus one.
And then this other one year we have the highest prediction year matches in with this.
So we have plus one.
So here we have three divided by four times 100.
This means that the top two categorical accuracy in this case is equal 75%, unlike the categorical
accuracy, which is 50%.
Now with that, we go ahead and compile the model.
And that model, the compilers from this we have Adam learning rate, which we specified in the configuration,
the last function here, the Matrix, this and that's it.
So we compile our model and then we set now to train.
There we go, let's paste this out.
And here instead of this year we should have configuration number of epochs.
Then obviously we have our training data set and we have our validation data set.
So let's run this and see what we get.
Scroll down and that's it.
See our losses drop in accuracy, increase in and top accuracy, which is clearly higher than the accuracy
training.
Now complete, let's plot out the loss curves for the validation and the training.
As you could see here, both the validation and training losses all drop together, while the accuracies
for the validation and training also increase up to this point here.
So it's almost getting to a value of one.
Now, you could check this out here you see the accuracy, 97.8% year, 98.19%.
So the model is performing quite well.
We could evaluate this model on our validation data.
And here we have the net model that evaluates so we call the evaluate method and then we pass in the
validation data set, validation data set.
Okay.
So we run this and there we go.
We have a loss of 0.350.035 accuracy 98.33% top k or rather a better still top to accuracy 99.88%.
Now note that given that the model is an overfitting, the model keeps all the model's metrics keep
increasing.
What you could do here is increase the number of epochs so we could train for more epochs to get even
better results.
Now we're ready to test out this model on some image in our testing dataset.
So here we're going to have this image or let's call it test image.
We have test image, which is going to be red or which is going to be this image we're going to read
using OpenCV library.
So we have your CV to read.
And then just in here we just open this up and the test.
Let's take up, say happy, we take all, we copy this path here, copy this path, paste it out here.
There we go.
And then we're going to convert this into a tensor.
Let's close this we have here now our test image or let's say M is equal to F dot constant test image.
And then we're going to specify the data type.
So your is a float 32.
And then with that, we're just going to pass this.
So let's let's print out the output.
Let's first of all, print out the shape, see, see the image shape 90 by 90 by three.
Then we're going to pass this into our model directly, because as we had designed this, we have put
in the resizing in the model and the rescaling tool.
So we're going to resize and then we're going to rescale in the model such that now we do not need to
do that out of the model.
So that said, let's get back here and all we need to do is call all in that model.
But before calling that, we need to do add one dimension since we passed this input in the model as
batches.
So we add the batch dimension here to expand dimensions and then we have the image to specify the axis
zero.
Okay.
So once we have this, now let's have our little net model which takes in that image.
So here we're going to print out this output or print out what our model gives us.
We get in this error here where we're told that there is this incompatibility issues between the input
image and what the model expects.
That said, we get back to the model and we notice that we didn't actually put the resizing.
So let's get back here and we have this resize rescale layers which we had built already, and we put
that instead of this rescaling, we have this resize rescale.
So we make sure we resize and we rescale.
Okay.
Now next thing we have to do is we have to modify this year because you're by doing this, we suppose
another input is going to be 256 by 256.
But here's what we will have is that we will have this known.
So our input could be any of any dimension, but we are going to do the resizing here.
So we have the resizing in this resize scale layer and then we also have the rescaling.
So that's it.
Let's run this.
There we go.
As you could see, you have from your we have this 256 by two, 56 by three.
And that's because we've actually passed this input into our resize scale layers.
So let's go ahead and retrain our model.
Your training and validation plots for the loss and accuracy.
And with this, we could go ahead and test our image.
So let's run that.
And this is what we get.
As you could see here, we have practically 00.99 and then almost zero.
So this shows us clearly that our class, the class one in this case, because here this is our class
zero.
Take that off.
This is our Class zero, Class one and class two.
So this image is of class one and is correct because this is a happy image.
So basically, you see how to create this image here, this image array from the file path, and then
convert this into a tensor, which is then pass into the model without any preprocessing.
Another thing we want to do is to actually print out the class.
So what we can do here is instead of this little net model, we'll have tfte ARG max.
So we'll look for the class with the highest probability, which in this case is this one.
We'll look for that class.
So let's hear the ARG.
Max, we specify the axis.
Now, if you're new to this, you could check out our previous sessions where we treat these kinds of
functions thoroughly.
So here we have that.
Let's run this.
You see, we have zero zero.
No, this is T of the max.
This is negative one or one.
Let's say negative one is the last axis.
Okay, we have that you see picks out this here.
And then from here let's convert this to non pi.
And then from here we use the class names to get this name.
So there we go, class names.
We run that.
We given this.
Let's see what we obtain before this class names.
Let's take this off and also take this one off.
We run that.
Okay, we have this list so we should take the zero element.
There we go.
Now we have that.
We put in the class names and we get the name.
So that is it.
See, we get the name happy.
Okay, so with that, now let's do one.
Let's test let's take SAT, for example, and we'll see how easy it is to carry out such tests.
Let's pick out an image here.
Let's take this one.
You could actually view this image here.
So that's it.
This one are the same image.
Take up this other one.
You see, we have this.
So let's copy this path.
Take this off.
Scroll up and then simply paste it here.
So this is the path we try to know exactly from the model what kind of image it is.
So is here.
It's a sad image.
And this is from the test set.
So make sure you are doing this kind of testing with data the model has never, ever seen.
Okay, so that's it.
Our model is performing quite well.
We can do something similar to what we had here, but with the difference that instead of just giving
out these labels, we give out not only this labels, but also what the model predicts.
So let's copy this code here.
Get back to our testing.
There we go and paste it out here.
So again, we're going to use the train with the validation data set.
So there we go.
We have our validation.
They said we have this plot.
And then at the level of the title we plot, let's have this true label right here, and then we will
have the predicted level.
So let's have this.
We move to the next line and then we have our predicted level.
Yeah, predicted level.
There we go.
And that's fine.
So we have this predicted level and we'll get it from here.
So we could simply have the net model.
The net model here we have our net model which takes in the images, so it takes in the image, selects
a particular image, and let's do the let's expand them.
So we have expand dimension, take in that image.
Axis equals zero and we close that.
So we have this, we pass the net model and we have this output.
Now we are going to do something similar again to what we had here.
Basically, it's even this year.
So let's just copy this.
Let's just copy this and replace it right here.
So it's the same thing we're trying to do.
All we're trying to do here is actually passing the image into the model and get its class.
So we compare with the actual level.
So here we have this class names and this we have plus there should be fine and that's it.
With this.
Now let's run this cell and see what we get.
Scroll.
Here is what we get.
You see the model?
This is supposed to be true.
The model year doesn't perform quite well, unlike what we had in this evaluation.
So let's check out our code and see if there's any errors.
Scroll this way.
Here you see, we have m This was the images.
So we have that.
That's why you see, the predictor is always sad.
So we have always predictor label, always sad because we had taken or we had picked just one image
and it's not dynamic.
So here we have this images, we select the particular image and we run this again.
This should be fine.
We get in this error because we didn't add the batch dimension, unlike here where we added a batch
dimension before passing in here.
So let's get back and then we're going to replace that images the image with this code here.
So let's get back here and then replace this with this code.
Note that we've treated this already in previous sessions, so you could always check out if you new
to methods like expand DBMS.
Okay, we run that and see what we get.
Okay.
So that's it.
This is what we get.
You see, Happy, happy, angry, happy, true level, happy, predicted, happy.
Or let's see if there's any errors.
The model does quite well see no errors.
So it's almost 100%.
In fact, it's 100%.
Although the evaluation here shows 98%.
98.33%.
The next thing we'll do is plot out the confusion matrix.
So we're going to go through our validation data for M level.
In our validation data set, we are going to start the labels in this list right here.
So we have labels that append the label and then we also have predicted that append add the net model
which takes in the images.
So here we have what the model predicts and what the model should predict.
So yeah, we have predicted create this list and then labels.
We also have this list.
There we go.
So we have now this.
That's it.
So with this now let's run the cell.
And then before moving on, we will convert this to a non P format so we could easily manipulate it.
So we have this as non pi, we run this again.
That's fine.
The year we could print out the labels.
We have labels.
Let's print this out.
There we go.
You see the labels, the different levels.
Now let's try to flatten out all the different labels right here.
So let's have this to be flattened.
Now let's scroll up.
See this?
They are in batches of 32, so.
We can actually see that you're scroll down a bit.
You see, we have this batch here.
Then we have the next batch and so on and so forth.
But then this output format isn't exactly what we want.
What we want is the classes that the class with the highest core.
So instead of this one head representation, we want the integer representation.
So what we're going to do here is use the max.
So let's print out the agg max of this.
Oops, Let's get back up.
Let's print out the max of this.
There we go.
And then we specify the last axis.
So we have that and we run that or we get an error or we have this error.
Now let's let's do this.
Let's pick out or let's simply select your up to the last value.
Now, this error should be coming in because we have batches of 32, but it happens that if you have
a data, let's suppose that you have a data set of 48 items.
Now if you break this in batches of 32, then you have let's let's say 98.
Okay, So here you have the first batch 32, the next batch 32, the next batch 32.
So here you already have 96 elements and then the last batch will be two because you have you want to
have 98 elements here.
You have 96 plus two given 98.
So because of this last batch here, we get we get in this error here.
So because of that, we get the error.
So what we could do is print right up to this last batch.
So let's let's run that.
So we're not going to pick out the last batch here.
We're not picking up the last batch.
So we go from the first batch to right up to the batch before the last one.
So let's run this now and you see that, that's fine.
So this works out well.
We could even print out, say, the first two batches.
Let's print out the first two batches.
So you see what that looks like.
See, this is the first two batches.
You have this here and this.
Now, from here, you could actually flatten.
So you could do this, you flatten this.
So you get all this in this single or one dimension list.
So that's why we want to get now let's move on.
So let's get back to this.
We have right up to the last batch.
We run this and there we go.
So this is what we get.
So we've actually flatten out all these elements.
Now, if you print out the length of this year, see, you print all this length, you see you have
6784 elements.
So now basically we want to compare this different predictions here.
We want to compare those predictions.
Let's take this length off.
Want to compare this labels, sorry, you want to compare all these labels with the model's predictions.
So here we could repeat the same process with a predicted let's have predicted or predicted.
We run that.
You see, we have this two lists here.
You see already that they are quite similar, although this one misses out.
So what we're doing is we have in this list and this other list, this for the predicted and this for
the labels.
So now that we have this set, let's define all as we define our pred, let's say pred, we'll call
pred to be this year.
So this are print which will flatten out.
So these are the different predictions by the model.
And then this is what the model was supposed to predict.
So the other labels so spreads and levels.
Okay, so let's have that.
We run that cell and then we get back to the code for the coefficient matrix, which we had previously.
So basically here we are setting the previous sessions.
We define this threshold because we have in binary classification problem here, since we have different
classes, we wouldn't define that.
We would just simply pass in as here this different predictions.
So for the labels and for the predicted, we have that.
Let's simply copy this out and paste out here.
So we've seen this already.
Let's take this off.
Now we have label and then here we have the predictions that we go, we're going to print out this coefficient
matrix, We have the figure and that's it.
So let's run this and see what we get.
There we go.
We see already here we have this conversion matrix.
And one thing you can notice straight away is that the most values are the leading diagonal has those
elements with the highest value.
So is here we have the highest values here.
And this is normal actually, because when you have this conversion matrix like this, let's redraw
this confusion matrix where you have this conversion matrix like this, this is a class zero.
So let's say class zero is angry.
So this is class angry.
Yeah, Happy and sad.
Now you're angry.
Happy and sad.
So.
Whenever the prediction or whatever what the model predicts matches with what it was supposed to predict,
you have an additional one, which is other year.
So we simply go through all the different model predictions for the validation and you see that 1472
times for 1472 times the model predicted angry when it was actually angry.
So this is correct now for happy.
You see 2000.
Here it is matches year 2890 times the model predicts happy and the actual was happy.
And here we have in 2198 times the model predicts that when it's actually sad.
And then here we have 21 times the model predicts angry when it was happy and then 26 times the model
predicts angry when it was sad.
Then we have 20 times the model predicts happy when it was angry.
Here we have 27 times.
The model is happy when it was sad.
Here we have 30 times the model.
Pretty sad when it was angry and we have 100 times the model predicts sad when it was instead happy.
So there is you see, this is the highest call we obtain for the wrong predictions.
And so this means that the model has that tendency of predicting sad when it's actually happy.
You can also observe this plot here.
You see this lighter colors this year.
As we go up, we get to this higher values here and then this and this.
So the lighter the color, the higher the score.
And then the darker the color, the lower the score.
Now, obviously, the ideal case will be where we have this purely white.
So we have this purely white, this purely white, this purely white.
And all this year completely dark with all zero values.
So that said, we've looked at how to have the obtain the confusion matrix, which is an important evaluation
metric.
And here we could also change this to training.
So anyway, you just have to have your training and I'll be fine.
Now we have to deal with that last, the last batch which did not take into consideration.
So what we could do is we could do some concatenation here, so let's do concatenate concatenate and
then we have that, then let's copy this, We just copy this and paste out your copy and then paste
it out your.
There we go.
But then we're taking the last element.
So instead of the elements before the last, now we're taking the last element and that's it.
So we add, then we add in the last element here so that we could actually flooding it out separately
before concatenating it with the previous elements.
We saw that having all of this joined together will cause an error.
So that's why we why are we doing this year again?
We copied this year, let's copy this and then paste it out here.
That should be fine.
This for the predicted.
So let's change this to predicted predicted.
Okay, so we should have that fine scroll this way and then let's have concatenate.
Okay, so let's run this and see what we get.
We get in this error.
Let's add this here.
There we go.
We run that again.
That's fine.
And the same should be for the predicted.
So let's run this again.
Get that error, scroll this way and add this year.
Okay, so we have this, the last batch which has been added up, and then we simply copy this and paste
your.
So now, instead of having just the all the values before the last, we have now all the different batches
together.
So here is for the predict, not just for the label.
So let's put this here we have the labels and then this is for the predicted.
So copy this, get right to the end and we have that.
So here we have this for the predicted space this year and that should be fine.
Let's run this again.
We run that and then we run this and there we go.
See, we have slightly different answers now.
Okay, so that's it.
We've seen how to plot out the coefficient matrix for multiclass classification.
Before we move on, we notice that we've made a very big mistake here.
As with those validation data set, we actually pass in the train data set.
So let's modify this and make sure you never make this kind of error.
As if you make this kind of error, you feel like your model is performing well, whereas we are validating
on the train data.
So let's we run this again.
I have to run this again.
Now training is complete and we see that the model wasn't performing as well as we thought.
You see here the last drops and then at some point starts increasing while that of the training keeps
dropping.
And then for the validation we have as accuracy going towards one as we have previously, whereas for
validation you're it plateaus at around 75% as you could see your in this values.
So you see the validation accuracy.
The highest we have here is like 75%, although the the top key accuracy is around 90%.
So that's sad.
We see that.
We see clearly there are models and performing that well.
And the next sessions, we'll see how to better for this model performance here.
We could also run this evaluation have the evaluation SEER 7590 and loss of one let's run this testing
correctly classifies this next we're going to try this out to see previously we had generally 100% because
that was on our same training data.
Now here you see let's start from up.
You see wrong prediction, right, wrong, wrong.
You have your wrong, right, right, right, wrong.
You see you see that out of the 16 different predictions, we have ten out of 16, Right.
So running that you see, you have 62% on this little sample which you took here.
Now, we could also plot the conversion metrics.
Let's run this.
And you could see clearly from here that the model isn't performing as well as it used to perform when
we're making that error.