Hello.
Welcome back.
In this lesson we're going to test a wall to lay a new network model that we created.
So I'm going to call the function does the name of the function to layout and then model.
Copy this.
Come over here pasted over here and then.
This function is going to return a dictionary called parameters.
And this is going to you know give us the parameters that we use for prediction.
So I'm gonna see parameters
equals this I'm going to store the return into another dictionary which we shall call parameters now.
This function takes it takes the training example let's see the function takes x which is that training
X Y which is the training y.
They are dimensions and then um yeah.
Then the Delenn and great as we see over here the number of iterations.
So let's grab our screen X from here.
Have a typo here I would just fix this.
No I'm going to copy train x.
I'm gonna put it over here
and then train y
we should have train y somewhere
let's see.
Right.
Train y train Y from here.
P sit over here.
And then lay dimensions.
We already have layout dimensions.
Um we can just create over here.
I'm gonna see this then it's got dimensions because we're going to pass an X which we created earlier
and H and then and Y we have these variables here
right.
A number of iterations.
We can set a number of iterations.
When I come off I hear when I see a number on this call iterations I can say this to let's say three
thousand or perhaps two thousand five hundred.
Okay let's start with this and see the performance.
Okay let's see.
Okay.
So after after training we're going to have our parameters stored in this dictionary.
Um let's see our predictive function that we wrote.
I'm gonna come to our library.
We have a predictive function okay to predict function takes x y and z parameters.
Okay.
So we can predict once we've trained I'm gonna come over here and call it a predictive function I say
predict and then what are we going to predict with let's try predicting what we train in values.
So I say train x.
We compare that to the test values train X train y
and then the last argument is parameters
and we're going to store this in a variable which we shall call
train prediction meaning prediction from the training set and then we are going to predict again we're
going to create another variable called Test prediction
which is going to hold prediction from the test set.
And over here we are going to pass test x
test y.
And of course parameters copy paste over here like this.
Okay.
Um yeah.
I think we can print
the train
conviction is a plus here SDR then a print trend prediction trophy to pic to paste over here and then
I'm going to print the test prediction the test prediction is plus SDR.
When a print the test prediction copy paste over here.
Right.
So we can build and see what we have.
Let's see how many arrows we get control as to save.
Click over here run module
number of iterations.
Okay so there's a typo here.
Line fifty seven.
This should be on a control is to save
and then click here to run more to.
Not a typo like sixty one.
Sorry but the compute cost the best way to find typos is to run the module.
Okay let's run again.
See name is not defined.
Line 67.
Yeah I'm sure we meant to write up to Z.
This one is in a war plan in library line 67.
Line 67 should be up here somewhere.
Come to see here.
Contra s
gonna run again.
Run module T W not defined line 67 again.
Line 67.
And this time is in our actual script.
Not a library line sixty seven sixty seven.
Okay.
They should be kept to top w you control S.
Click here to run the module DP to line seventy right.
So DP 2 is not defined is because over here I wrote DP 1 instead of TB 2.
Just bear with me.
So let's see do we have any arrows anymore arrows.
Okay DP 1 over here is in our library.
Line ninety five in the library.
So um perhaps you can see reduce this a bit.
So we have an arrow in the library.
It says line 95 of the actual script to lay in.
Okay let's see.
Line 95.
It says What does it say.
D W one key arrow T.W. one y ninety five.
Key arrow
Kristen K.
huh.
SC to predict this you predict.
Function
right the arrows from this over here you know where to lay a neural network function that D.W. won here.
I used a small w so o change you took up to a W.
Let's see if we have any further arrows country s to save run module.
Cost is not defined.
Let's see.
Yeah.
This has to be a plural costs.
I suspect.
Let's see hmm.
Okay so is talking about a single cost.
When we completed a cost here this there there's a typo here with double C or clean.
This contract is to save the C run more to follow.
No more arrows.
Now we're in training mode.
Okay I can see the arrow is reducing.
We've got to wait for a while.
I'm gonna minimize this.
Okay.
And like we stated in our function we print in the um did cost every one hundred it iteration.
That is why we start from zero then one hundred and two hundred then 300 400.
And we said we wanted I think two thousand five hundred iterations.
We trained in forty one thousand five hundred iterations and now the error has drastically reduce this
graph for the error reduction.
We started over here to a point seven and then we came.
We call here okay.
So when I close this graph um it's printed in predictions but it's our accuracy is the accuracy for
the um for the training set.
We test that the prediction on the training set the accuracy we go to zero point zero point nine nine
for the test set we go seventy two percent we've got nineteen ninety nine percent for the training set
and then seventy two percent for the test set.
Um and I think this is higher than what we saw in our uh uh what other model the logistic regression
what I think we had it at 69 or 70 percent but anyway this the accuracy we got we can actually um test
with our own image.
So let's do the um print in the train prediction and the test prediction I think is rather difficult
to make meaning of this.
So what we're going to do is create a function that would show us the images that were missed predicted
that you made this word a wrong prediction or could as well as test with our own image.
Okay so I'm going to close this now and then I'm
gonna clean this up now.
I'm going to create a function to show us the images with which we did and uh perform well.
Okay I'm going to write a function here which I shall call print wrong predictions
and we shall use the classes from our data set and then X Y and then the probabilities P and
so we have the classes our images our training X the labels and the predictions.
Okay I'm going to create a variable here a no C E course P plus why not come here and see
mislabeled
indices because non pi dot as array
and p dot were
a course won.
Okay so then I'm gonna say I'm gonna set the default size of the plot.
We're going to put the images of the wrong predictions as well and see which images we had difficulty
with.
So C P O T R C firearms 10 0 c
figure that fixed size
equals simply C 30 30
and then once that is done I'm going to come down here and see no more images because Len Len of mislabeled
indices
index you like this then I'm gonna use a loop come down here for I in range
of images.
I'll see
index because it's labeled indices
one index I over here.
Now I'm going to plot them.
I see a penalty let's not subplot
two comma number of images just over here.
Plus one and then I'm going to use I am sure by saying P L T dot I am show
X
comma index
then reshape this.
Remember our image is sixty four by sixty four by three.
So I'll do it or to reshape
and then interpolate say interpolation of course.
Nearest.
Then once that's done
I'll see I just said a Title VI here.
Peyote title.
Call this protection
plus classes.
Remember we get classes from our data set when we load data we load a classes as well.
Okay.
Plus classes index sheet into typecast into VI here and then P and then zero comma index.
And then dot
we decode this to UTF 8
plus
append a new line here.
Then kind of corrupt the Y
classes
y index 0.
Index
then decode
to UTF 8
right.
So let's check if we have some typos.
They should be able to call this function we should be able to sort of display to the wrong predictions
that we made.
So now we can call our function print wrong predictions.
Call this over here and I'm gonna pass classes.
The classes we got from our dataset
and then I'm gonna pass a test.
Um our ex is gonna be the test.
X or Y is gonna be the test.
Y
o predictions is going to be these predictions.
We go from predicting the test which is over here test predictions.
Paste this over here.
Okay.
Once they down our Popeil Tito show over here.
Right let's build and see what we have or just verify this function has an end.
Okay.
Right.
I'm gonna click over here to run the module invalid.
Yeah of course there should be a comb my hair
click over here.
Run module.
Okay.
It s training.
Right.
So this the graph close this and we have an arrow test.
X is not defined.
Goodness.
Come all the way down here.
And then we find the arrow.
Okay test X X because this should be a small x not a capital X..
I'm gonna run this again.
Okay.
Straining
Okay so growth
okay we still have some arrows actually.
Image object personal property code interpolation.
I may have may have missed um mis spelled the word.
Yep I think.
Okay yeah.
There's gonna be a lot of error fixing when we are doing life programming.
So the word should be interpolation.
And the one that I'm gonna actually do over here is turn off the axes.
I do PR T dot axes and then I'm gonna see off like this.
Okay interpolation.
Okay.
Right.
I'm gonna run again
this graph.
Okay so this is where we made our mistake.
Um
okay.
So in a way you see a cut.
It s means we predict like we predicted.
No cut.
So we weren't able to predict this correctly and we missed 2k butterfly for a cut.
We saw a cut.
We said it wasn't a cut.
We mistook this for a cut as well.
We couldn't predict this.
We mistook this for a cut.
We couldn't predict the number of cuts.
Let's see.
Um
okay so that text is not very clear.
I'm trying to expand this to get as player as possible.
I'm going to increase the size of this.
Not that it matters but I'm going to increase the size of the images so that we can't see where we made
our mistakes.
I'm just gonna come here and set them to Fifty and fifty control as I'm going to train again.
So this is our graph.
Okay right.
So anyway yeah.
Wherever you see a cut we made a mistake there.
We predicted it as non cut and wherever you see something that is a cut we mistook that for a cut.
So yeah there's the performance.
We have 72 percent accuracy.
Later on we shall see how to perform the same task with other neural networks.
We shall try this which convolution our neural network and we'll realize that performs better than this
and given a small amount of you know data said we've trained I am not alone.
72 percent is actually a very good um a very good accuracy.
Anyway let's move on.
Let's try with our own image.
Um I'm going to um load in an image like we did before.
Um okay.
I'm going to comment about this the bit that shows I'll put a comment here for you on comment to show
wrong predictions
right.
So now I'm going to load an image I'm gonna see my image my image because we have an image you know
what.
You may just fold I know Scott's image or we just rename one to cut image my image of course cut the
JPEG and um
I'm gonna
I'm gonna come over here and see phoneme f name because I just create some line here f name equals images
folder slash plus my image
patient over here and then I'm gonna see image cause and Pitot Ray then we're going to do indeed that
image that I read.
Actually I'm going to take a look at the D python library or the python module we use for you know processing
the image in our cut or no cut lesson because I remember one of the um the modules who were using one
of the libraries was deprecated and we had issues with that so I'm going to see what we did in there.
So this is our cut on not projects I'm going to check.
No h over here
over here.
Okay.
So this is how we did a prediction.
I'm simply going to quote uh copy this.
I think is almost the same as Yeah.
I'll paste this here and this should do the prediction for us.
Over here we are checking image number six in our images folder and then we predict.
Let's.
K
um
let's see the image.
How about that.
We said he made six.
We see estimate six image six is this but okay.
Image six is this but over here.
No images for the
This over here.
I'm gonna change it to.
I think I'll predict function.
You should be w and this should be the W has to be capital.
I suspect.
I don't know what are we made a small w in our previous cuts or not projects.
But I've changed from small W to capital W here.
Now let's run and see what we have.
I'm gonna click here to run the module
it's training.
Okay.
And the image is not defined okay because we're not included in the image if not imported it yet.
So we've got a imports that goodness from all over the place today.
So I'm gonna say from side by
import and image.
Okay let's run again.
Okay
to name D is not defined.
Okay let's see this image prediction predicted T W DP says the name D no defined mm mm mm mm mm mm mm
mm mm mm mm.
Let's see what our predict function looks like.
Um you've got to forgive me.
Yeah.
Um perhaps to predict function we wrote for this new lesson is different from the one we used in a you
know other lesson.
Yes certainly to predict the function that we wrote for this is different from the one we used in our
cattle or not.
In
um this is it.
There's that cat on not to predict of course it is different this neural network is different.
We've caught our red blue activation.
And then we've got a sigmoid the cat or not.
It's a simple logistic regression.
Um so indeed.
Sorry about that.
Really.
But yeah you learn these things.
Um we're gonna write a predict function from scratch for our new our new example here.
Um.
Um we have our predict function we going to write the part that predicts using our predictive function.
Okay.
So I'm going to write the I'm sorry I was trying to be lazy.
See laziness is but it's a lesson okay.
So we start off by selecting an image the path for the EMH and we see image because N.P. a re in the
image read flatten and then over here we said My MH CI pi MH and then the image size and then we reshape
it to our standard image size.
And over here image prediction I empty prediction of course predict.
Okay over here what I'm gonna do is I'm going to say predict
when I see my image is the image caught my image.
Image predicts image.
This one here
my image actually.
Why did I give this and this the same name.
I call this my AMG my m predict my AMG.
Copy this
and then we need our y labels.
I'm gonna pass
a creative variable here.
Remember our predict function takes x y and z parameters.
So we've got a past the y value of the image we are predicting what a tiny image or not so I'm gonna
create a variable here.
Um I shall call this my Y label.
My y label on my label y.
This equals zero cause image number six.
It's not an image.
It's not a cut.
I m g six years not a cut.
Let's see what are the neural network would be able to distinguish that show.
I'm gonna pass the Y here and then I'm gonna pass parameters we have parameters from somewhere.
Okay.
This the word parameters just pass this over here.
Over here.
My label y and then parameters.
Okay.
Then we showed each image.
Then we squeeze.
Okay
prediction is we simply okay.
Put what did prediction is correct or not.
Okay.
I'm gonna run this and I'm gonna skip that train in bit I'm gonna post the video when it's done training
we do it.
Okay so we've done we're done training parameters is not defined in Kristin
parameters is not defined.
Okay let's see.
Yeah.
You generally need to forgive me here.
Cause when we when we did our training we started that result in a list called Para parameters.
This typo here you see.
So this is where our problem is.
This is para.
This should be parameters with an E but it's called parameters.
So when I come in I call it s you know what I predict here.
It couldn't recognize it.
So I generally um request for your forgiveness.
Yeah.
Um show parameters.
And then we pass it.
Okay.
Let's run it.
I'm gonna save this.
I'm gonna train.
Okay.
We still have an arrow somewhere right.
The arrows because I copied pause here and pasted it as arguments over here.
We have to change the typo from here and here as well.
Let's run again.
I'm gonna train.
Okay
okay so this is it.
Um there's the image.
Oh I.
One is complete because your prediction says a zero.
Our neural network was able to tell us this is not a cut.
The prediction is zero.
A crazy one.
Okay let's try another another image this time let's try an actual cut.
Let's go to our images folder and I'm going to select how about I am G2 gonna come over here.
I empty to end the Y label of I am due to the actual y is 1 meaning it s a cut.
Now let's run this
okay and okay we could predict this to be a cut.
So as you can see it says the accuracy is zero.
Prediction is zero meaning we were supposed to predict this as a cut but a neural network wasn't able
to predict this.
Therefore our accuracy zero and the prediction is you.
So you can try to edit images and um you can download more images from the Internet to try and um also
you can play with the um the hyper parameters of the new network and currently our hyper parameters
is the number of hidden layers you can you know use 10 hidden nodes and see what you get.
You can also play with the um the lending rate and you can play with the number of iterations to see
whether you can get better down to 72 percent accuracy.
Currently our accuracy is at 72 percent so you can change the head in a number of feet and let us make
this an H.
You can use more n h value to see you can train longer you can certainly play with the learning rate
to see what you can get something better than seventy two percent so far this what we have and you can
test with more images different cuts images and see what you have if you have any questions just send
me a message and I'll see you in the next lesson.
All there is.
See you later.