There's a really exciting time.
Dog vision is officially coming together.
So now we've got one function to visualize what our model's predicting.
We left off the last video saying it might be helpful figuring out what other predictions our model
is making.
So let's first go back up.
We'll take off this tick off all of these because we've made a function that does these
emoji
so let's come back.
All right a little instruction set for ourselves.
Now we've got got one function to visualize our models predictions.
Let's make another or our models top prediction.
Let's make another to view our models top 10 predictions.
Mm hmm wonder how we might do this.
You start thinking I'm going to keep talking the function will we're probably going to need the input
of the prediction probabilities array as well as the truth labels because remember all comparisons when
we're evaluating our model.
This is we're up to a lot of times evaluating a model is just comparing what the predictions are to
the truth labels in supervised learning that is.
So we go here we'll go take an input of prediction probabilities array and ground truth.
All right.
And an integrity similar setup to what we've got up here and then what's it going to do.
It's gonna find the predicted label using get pred label
it'll need to find the top 10 of a few things.
So find the top 10 we'll go here.
Prediction probabilities probability indexes.
Sorry prediction probabilities values.
And then finally the prediction labels
and then what we're going to do is plot the top 10.
So plot all of those.
That's basically all we're gonna be the top 10 prediction probability values and labels coloring the
true label Green another era because that's not marked down.
Now what this is called is kind of top 10 accuracy or top 1 accuracy.
So you'll see in classification models and whatnot there's top 5 accuracy.
So it's the accuracy of your model.
If you included the top five predictions.
So it's usually higher than the top one prediction and if that doesn't make sense we'll put it up and
I'll show you.
So let's make this is gonna be a bit of a beast of a function because that's what we're all about.
Big Dog functions on dog vision prediction probabilities labels and equals one.
But we've got a lot of momentum from what we've been doing above we've trying to full blown deep learning
model and the other thousand images but that's right we're gonna scale it up soon and we're starting
to visualize what our model is capable of plus the top 10 highest prediction confidences.
That's what we want to do along with the truth label for sample in that makes sense.
So pred prob true reliable we need these two things equals prediction probabilities and labels.
Wonderful get the predicted label spread label.
Just gonna be using our function that we've used before.
Get pred label
prayed prob and now we're going to find the top 10 prediction confidence indexes.
So this is what we're looking for.
We need to find the top 10 because we've just done this.
Let's take these off while we're here.
Beautiful.
So find the top 10 prediction.
Confidence indexes.
So before we do this in a function it's probably easier.
I could just type it out but that's not a lot of fun.
If you're not sure what's going on and what I mean by this let's just cut it out first.
Come on Daniel stop talking predictions.
Zero dot org sort.
What's.
OK so let's have a look at this okay.
So what this is ARG sort is doing for us if we go predictions 0
it's giving us the order of indexes that will sort this array so the highest value is here 1.
So somewhere there.
There we go so if we were to put all of these indexes in order this array would be ordered.
Let's see that in action so negative 10.
Because we want the top 10 what happens
100 Now what if we go reverse that invalid Index.
No scalar variable.
Mm hmm.
Well that's interesting.
How would we fix this.
I think what we might need to do.
Grab the prediction probabilities.
All right.
I figured that.
There we go.
That's what we missed
this little bad boy I say when you're slicing when you're slicing and dicing.
Always be careful.
Same rule when you're using a knife.
Always be careful so that's a rule for slicing.
What is this.
This is the top 10 values so the top 10 indexes we want to reverse this.
There we go.
So here's the top 10 values of prediction 0.
So what if we went predictions 0 then indexed it using that two point one six figure up here two point
1 6.
That's the max value.
So let me just one last demonstration to know what's going on.
Don't max
two point 1 6.
There we go.
So there's the top 10 prediction indexes.
So this is the prediction values as well.
But if we remove this these are the top 10 indexes of prediction 0.
So that's what we can do.
We can take this and put it up here.
So top 10 pred indexes equals pred prob the ARG sort negative 10 colon.
If you're wondering what this double semicolon or double colon negative one does it reverses this that's
all that's doing.
If we took this here notice 17 is at this end and if we go here it's at this end but we want it in descending
order so we do call and call a negative 1 beautiful so it come back up here.
Now we want to find the top 10 confidence values.
Now this is pretty easy now because we can just take this index here find the top 10 prediction.
Confidence values and remember how I said prediction probability and confidence values kind of the same
thing or at least colloquial Fred prob and we want to take top 10
Fred indexes because we've already just found that so would be the equivalent of going predictions zero
and then give me these indexes to the top 10 values of prediction 0 in descending order so we can take
off two of these.
Look at that look at us working through these functions like nothing.
Boom.
So what's next.
What do we need to find.
The prediction labels.
All right.
That's not too hard either.
Find the top 10 prediction labels.
Now one should have think about this.
If we've got the top 10 prediction index values how could we use those to find the top 10 prediction
labels.
This is where unique breeds comes back into play.
So top 10 red labels equals unique reads top 10 10 as if it's the start red indexes.
Well look at what we've got.
We've got all these top trends.
Let's just copy and paste this copy if we want to see this in action.
Let me just show you here so unique breeds top 10 credit indexes so we could take this.
This is the top 10 indexes and unique grades plot that will index it on that amazing.
So these are the top 10 labels that our model has predicted for prediction zero.
So item 0.
Now we need to set up a plot set up plot.
We've got a top plot.
Call it something simple we want to bomb plot so NDP arrange Len top 10 pred.
So these are the x values.
So I want my x values of my bomb plot to be the prediction labels.
So you'll see what this looks like in a second and then after that we want the top 10 Fred values.
So this is the prediction probabilities for each of our samples.
And this is the color gray.
Now we want to go plot x ticks is NPV a range.
Len top 10 Fred labels.
So this is just saying that we're creating NPA range land top 10 parade labels is because we want a
range of 10.
So we want 10 bars on our plot.
And now we want the X ticks to be the names of our top 10 pred labels a.k.a. these.
So along the bottom of our bar plot we should have the labels of our top 10 predictions here.
Labels equals top 10 red labels.
And then the rotation is vertical because otherwise if it's horizontal and the X ticks just strings
that's going to get out of control and we don't want that.
And one final thing we're going to add some color change the color of the true labels of the true label
appears in the top 10 so NDP is in.
Which is just if something is in something if one value this value is in this array color it Green
will go top plot
and then we'll index it.
So NDP Max so the maximum value of top 10 at pred labels equals true label what is the index of top
ten read labels.
Where is that equal to true label.
Get that and then set the color of that index to be green.
Else pass.
We don't want to worry about that far out.
That is a lot going on but let's see it in action if in doubt run the code and again if you want to
test out what's going on in each of these functionalities don't forget you can always break it out.
So plot thread comp prediction probabilities equals predictions
labels equals vowel labels and N What do you want might be number nine.
What's happening here.
Unique breed.
We got a typo as usual.
Unique breeds
and again rotation vertical spelling vertical wrong.
Vertices El plot trade cough.
There we go.
Check that out.
So this is pretty cool.
So along the bottom remember what we said we're gonna do.
We're gonna go to the X techs are the top 10 prediction labels so these are the top 10 predictions that
our model is made.
And as you can see the first index one the.
So this is the predicted label because it's got the actual predicted label because this is got the highest
value prediction value and these are the other top 10 value so you can see how they go down after the
top value and the true label is the one in grain so Border Collie.
So when our model is done as predicted Collie but the correct prediction is actually border collie.
Now to me that kind of sound like the same thing.
Let's figure that out.
Let's go.
Collie dog images.
Border Collie.
Well Mm hmm.
This doesn't really make sense to me Border Collie
so even Google Images doesn't really show images of colleagues it just shows Border Collie so you can
kind of see why our model I predict Collie instead of Border Collie.
But it's also predicted malamute what's a malamute malamute o okay.
Well you can kind of see a dance got black and white just like a border collie.
So this is where we're starting to really understand what's going on with our model.
Let's delete some of these cells in the next video.
Now that we've got these two functions that it can plot some intuitive understanding of what our model's
predictions are doing.
Let's take this one off here.
Let's write some code to combine these two plot spread and plot pred conf to have the image over this
side and the top 10 prediction comes on the right so maybe we could do it for 10 images or something
like that but I'll see in the next video.