YoBro 14 May 2020

Up next

Mobile Network Problems Inside Your House?? आपको ये जानना जरूरी है !!
15 Oct 2020
Mobile Network Problems Inside Your House?? आपको ये जानना जरूरी है !!
YoBro · 1 Views

Beginner Intro to Neural Networks 11: Neural Network in Javascript


JS Solution: https://jsfiddle.net/wbkgb73v/

Solving the flower problem.

Our farmer wants to predict a flowers type, only knowing the width and length of its petal.

Here's what her data looks like:

length width type
3 1.5 1
2 1 0
4 1.5 1
3 1 0
3.5 .5 1
2 .5 0
5.5 1 1
1 1 0
4.5 1 ???

She wants to predict that last flowers color, and also end up with a neural network that can classify future flowers!

She has two inputs, so her network will have two inputs, length and width

She has one output, so the network will have one output

It will look like this:

nn(length, width) = sigmoid(w1 * length + w2 * width + b)

She uses sigmoid to squash the values between 0 and 1, since the flowers only have two types, she can consider outputs below .5 to be blue and above .5 to be red.

Let's look at what this network can do already:

We scatter some points on the x-z plane and consider the x-axis our length feature, and the z-axis our width feature.

For each grid point, we feed its coordinates into the network and get an output, that becomes the points y coordinate.

Now, we can play with w1 w2 and b and see what they do!

If we removed sigmoid check this out!

Ok, pretty cool.

So now we need to train.

The training procedure is to pick a random flower from our data, feed in its length and width to the net, and get an output. Then we get the squared error of the output with what it should have been given the data.

For example, we pick this flower, 2, 1, 0.

We feed in 2, 1 and get out blip.

Because this is a blue flower we want to bring this output lower always.. as close to zero as possible.

Here's what the squared error looks like:

(nn(2,1) - 0)^2

notice that if we replace nn with its definition we just have a function of parameters

cost(w1, w2, b) = (sigmoid(w1*2 + w2 * 1 + b) - 0)^2

We take the partial of the cost w.r.t w1 w2 and b, which will give us three functions:


which tell us how to change w1 w2 and b to INCREASE the cost.

We want to decrease the cost, so we instead subtract these partials.

Refer to the cost function video in this playlist on why this works if its hazy.

We update our parameters using a fraction of these partials.. and that will bring the output of our net closer to what we wanted it to be!

Now we repeat with a new random flower, and keep going until our networks output looks reasonable.

Because our dataset is so small, we're not going to split our data into train/test which we should usually do. That's something I'll cover in more advanced NN tutorials.

Ok, look at that! The nets output is looking good.

And here it is in javascript! Thanks to Alex Non for kicking that off!

So now we have trained weights in javascript, which we can feed values in and get out predictions!

That's it for this beginner series... If you made it this far I'm proud of you haha!

My apologies that it was a bit disjointed and not as linear in difficulty as I would have liked. I've learned a lot while making this as well about content creation and the benefits of planning!

Going to begin series on general NN topics now, like deep learning and model architectures, also latest research topics and some of my own research into how AI is being applied today.

Thanks for watching!

Show more
0 Comments sort Sort By

Up next

Mobile Network Problems Inside Your House?? आपको ये जानना जरूरी है !!
15 Oct 2020
Mobile Network Problems Inside Your House?? आपको ये जानना जरूरी है !!
YoBro · 1 Views