10.3: Neural Networks: Perceptron Part 2 – The Nature of Code

This is a follow-up to my Perceptron Video (

This video is part of Chapter 10 of The Nature of Code (

This video is also part of session 4 of my Spring 2017 ITP “Intelligence and Learning” course (

Source Code from my first Perceptron Coding Challenge:

Simple Perceptron code examples:

Support this channel on Patreon:
To buy Coding Train merchandise:
To donate to the Processing Foundation:

Send me your questions and coding challenges!:

The Coding Train website:

Links discussed in this video:
My video on the map() function:
My video explaining object overloading:
My Perceptron Coding Challenge:
Session 4 of Intelligence and Learning:
Perceptron on Wikipedia:

Source Code for the all Video Lessons:


For More Coding Challenges:
For More Intelligence and Learning:

Help us caption & translate this video!






41 responses to “10.3: Neural Networks: Perceptron Part 2 – The Nature of Code”

  1. the colorful rainbow Avatar

    does anyone have the source code for this…I tried doing it on my own -> messed up -> tried fixing -> gave up -> cried -> and now begging for the source code

  2. Sonny Marinho Avatar

    Guy… Thanks for your video! You're awsome! =]

  3. Cameron Nichols Avatar

    I was trying to think about a way to have machine learning with tic-tac-toe. Maybe you could do something on this? I was thinking having different weights for every possible placement of the X or O, depending on what is currently on the board.

  4. Algeria Avatar

    realy, good job, well done, keep up doing the good staffs

  5. Julian Abhari Avatar

    Why does the formula that the neuron is trying to learn have to be equal to zero? The formula you wrote down was "w0(x) + w1(y) + w2(b) = 0" My question is why is it equal to 0?

  6. Kino -Imsure1200q Avatar

    btw why not use 1 instead of bias?

  7. ToTo Troll Avatar

    Ehm.. When copying and running your code I got an error in the perceptron tab. It says "ArrayIndexOutOfBoundsExpection: 2" about "sum += inputs[i] * weights[i];"

  8. Akash Kansara Avatar

    best video in series.. kudos.

  9. pow3rstrik3 Avatar

    If you are going to refactor, please change the x_ and y_ to x and y and just use this.x = x and this.y = y. (refering to the construction of point)

  10. mrrubikscubeman Avatar

    Shouldn't 0,0 inputted get outputted as 1 because of the activation function? I thought that after summing everything you saw if it was above or below 0 and then gave it a value of 1 or -1.

  11. Jono Koenig Avatar

    you're such a delicately beautiful whiteboard scribe. love it

  12. Daniel Astillero Avatar

    24:36 CAPTCHA of Daniel Shiffman

  13. gufi7000 Avatar

    Dear Senpai Dan/Shiffman/Daniel/TheCrazyCoderFromP5/TheCodingTrain

    I really like your videos!
    I attned to the HTL-Braunau (Higher Technical School – Braunau) with the background to learn coding.
    You are one reason why i want to learn the fascinating of coding.
    Your Videos are very funny but informing…
    You do your things with love and this is why i like your style!
    And one day I want to visit where ever you are and meet you to talk about coding things and your crazy but good ideas.
    I hope you will read this one day and say:"WoW… I changed someones life."

    Lg. David F.

    Ps.:Sorry for my bad english (I'm a 15 Austrian boy)

  14. cure 44 Avatar

    It would be really cool if u could do this series with java 😀

  15. Learn How Avatar

    Brick Breaker Game Coding Challenge

  16. The BuilderBoxGamer Avatar

    I have a question, do you do any ActionScript tutorials?

  17. Torny Avatar

    the coding train, could you do some basic example of unsupervised learning?

  18. Никита Богданов Avatar

    Try to make learning rate at the beggining of learning process time high and then make smaller and smaller for not thinking about him at all .

  19. zunair ahmed Avatar

    which programming language do you use.? and suggestions to learn it

  20. XKCDism Avatar

    Are you going to cover genetic algorithms combined with neural networks?

  21. Studio MZK Avatar

    Hey Mr. Shiffman! Do you think – at the end of this video – that the gap between the 2 lines represents the error value between the training set and the formula?

  22. zlotnleo Avatar

    Since you do training in draw() it overtrains it on the input data and any unseen data is very unlikely to be classified correctly in general case. In this case it would work since the line's equation is the same as the calculation in the perceptron. Also, splitting the dataset would allow you to estimate the accuracy and hence analyse if any changes you make are statistically significant.

    On an unrelated note, may introducing higher powers of inputs into the equation produce useful results? It's clear it would improve classification of points to either side of a parabola, but what would be the best way to generalise it to work with an arbitrary curve?

  23. Alex Shirley Avatar

    Hey Dan, I had a thought about your line function, will it still work if you input the formula for a parabola? Keep up the good work,

  24. Skizerz the Almighty Avatar

    is the perceptron series going to eventually go into neural networking?

  25. JoraForever Avatar

    i dont think that a line is a good representation of an equation, what if the equation contained square of x or root of x, the line will represent only the end points of the equation

  26. realcygnus Avatar

    superb content…..as per usual

  27. Robin Ranabhat Avatar

    i only know basic python .yet i understood our videos . YOU ARE THE REAL MAN

  28. alessandro77335 Avatar

    "Life is just one big refactoring" ~Daniel Shiffman, 2017

  29. ProCactus Avatar

    The last couple of weeks have been really easy to follow. Thank you for taking your pills before a video 😀

  30. Anna C Avatar

    This model can be used for data result proximity prediction by using more complex mathematics to create algorithms that have very low incorrect information feedback. Thanks for the video.

  31. Raj Krishna Avatar

    how to make the canvas responsive?
    plz rly

  32. Greyzor 6 Avatar

    geometry dash coding challenge!!! plis

  33. AgentZB Avatar

    I am making a video game, should I use p5.js or prosessing? p.s. you are awesome man!

  34. Lorenzo Calisti Avatar

    you can make a function that changes learning rate during time by it's own without using any user input(sliders and so..)?

  35. DaMastah Avatar

    You didn't have to scale down the m value of the line function. Dividing 3 by 10 doesn't "scale it down" but totally changes the slope of the function. (Also, thanks for another great video!)

  36. xZen Combo Avatar

    Will you make something creative and stop this machine learning xD?

  37. Kamil Bolka Avatar

    I have a question: How do you get display Density in processing so all my shapes stay the same size when I change the windows resolution?

Leave a Reply

Your email address will not be published. Required fields are marked *