3.1: Introduction to Session 3 – What is Machine Learning?


(bell dings)
– Hello, welcome to session three of The Nature of Code: Intelligence and Learning. So this is one of my
opening videos for these sessions. If you are watching this video
as part of that playlist for the Intelligence and Learning course, you will see a lot of videos in front of you with a variety of demonstrations
and different coding challenges. There will also be a video at the end, where I come back and pose some ideas for an exercise or assignment that you could try. But what I want to do
in this particular video is– Now, now is the time–
this course has just started with this little warm-up of thinking
about artificial intelligence, and search algorithms, and graph systems, and then we took this turn and thought about genetic algorithms
and evolutionary systems, but you might be here because you heard
about this term, machine learning, maybe even heard about
this term deep learning, and you want to get a sense
of what does that mean, what are the possibilities with
machine learning and deep learning, how do machine learning systems work,
what are they for, what’s the lingo
for this sort of stuff, and now’s the time to get into that. Now, session three here, I will not be using any neural network yet. So what I want to do in session three is just talk about what machine learning is, what its applications are. So something that I’m gonna cover here is classification and regression,
what do those terms mean, and what are some classic algorithms for performing classification and regression. And so, I’m going to look at something
called nearest neighbor similarity, K nearest neighbor. And I’m also going to look
at something called linear regression. And so these will be some
sort of classic algorithms that you can play around with
and actually do stuff with. And then in session four, we’ll start looking at
what a neural network is and see how we can use that
as part of a machine learning system. Okay, are you with me? By the way, I barely know how to do this stuff, so if you’re watching this for an expert, you probably wanna find somebody else on YouTube, but I’m learning this stuff, trying it out, and hopefully you’re gonna come along
and join me on the train, right? Oh, I forgot! We’re on a train.
(train whistle blows) On this ride on the train in the sky with me as your guide. Do sky and guide rhyme? I think they do. You’ll see. I had a point to this, but I digress. Okay, so what is machine learning? So first of all, one thing
that I might suggest for you if you wanna watch some videos about somebody who really knows
what they’re talking about, I would suggest Andrew Ng’s Coursera course. A lot of my knowledge and inspiration
has come from that course, and Andrew Ng does a good job of giving a nice introduction to machine learning. And two particular references– one is this definition,
this quote from Arthur Samuels, who is a pioneer in the
world of machine learning, defining machine learning
as a field of study that gives computers the ability to learn
without being explicitly programmed. And so here’s an interesting
thing we can think about. When we looked at the A* algorithm
in session one for pathfinding, we were designing, us the programmer, writing an algorithm
to specifically perform a task. The computer would follow those
instructions and get to a result. There was an intelligence to that algorithm, there was the disappearance of sort of
the computer solving a problem in thinking about it, but ultimately,
we had written the instructions, the code for the computer to solve,
to arrive at an answer. So what if, instead of us writing the instructions, we would just set up a framework
for the computer to figure out what the instructions might be,
what are the right parameters for some type of model to
perform some sort of task? So this is the idea of machine learning. And I would encourage you to look
at the work of Arthur Samuels. One of the things that he did was train a computer to learn to play checkers by just having it play itself over
and over and over again, thousands of times, to be able
to learn what a good strategy was. But ultimately– So one of the things that I want
to talk about here is– So let me come over the whiteboard here. I have this README that
I’ll link to in the description. You can read some of the definitions and information that’s on that README. But what I want to look at
is this model for, this– I’m gonna describe to you machine learning
in this particular way. So there is some sort of input. That input is going to go into
some sort of algorithm, some recipe. I think that’s a nice way of thinking about it. Some machine learning recipe. And then out of that machine learning recipe, we are going to get an output. The input into the machine learning recipe is typically numeric. So you could think of it as, you know, a classic example that’s always given is what if we want to build
a machine learning system that can guess the price
of a house based on some inputs. so maybe we might say something like, “Oh, the house has three bedrooms, “and it has two bathrooms, “and it has 1,000 square feet.” And etc., etc. This is the input into the machine learning recipe, and the output might come,
“The house is $1 million.” Something like that.
Nice house, apparently. Okay, so this is what machine– So typically speaking, another way of thinking about machine learning is making sense of data. So I have some sort of data and I want to make sense of it. I have some input and some output. So two kinds of output that you’ll see in most machine learning
algorithms are classification. Another kind of output is regression. So what you might not have realized here is this example that I gave to you, where the parameters of a house, a data point, goes into the machine learning recipe
and we get this price output, this is actually regression. Regression refers to predicting
some sort of continuous numeric output, whereas classification refers to
taking an input and classifying it into a discrete set of labels. So here might be another scenario. I have an image of a cat. That is the input into
the machine learning recipe. And the output is something like this. Well… I’m getting the–
usually the output comes numeric, so we have to sort of figure out
what this could mean, but I’m speaking in kind of
higher level terms here, so I’m just gonna say
the output is cat. I am labeling it–
and maybe the only possible options are cat versus dog, so what that output actually is is something like 0.9, 0.1. Like there’s a 90% chance this is a cat, 10% chance it’s a dog. So this is classification, attempting to assign a discrete label to something like an image. We could’ve done something with the house data using the classification. We could say, you know, fancy house, summer house, winter house. You know, we could classify into one of two categories. That’s classification. Regression, getting a continuous numeric output. So how does this work? So number one is we’ve got to, at some point, start talking about what are some different recipes that could go in here. And I could name you a few. For example, K nearest neighbor. This is a particular algorithm that can work for both classification and regression. I could say something like support vector machine, or I could say artificial neural network. And then there are a variety of flavors, so to speak, of styles and of artificial neural networks, convolutional neural network,
recurrent neural network. So this is something I ultimately intend to spend a lot of time on. What is an artificial neural network? How does it work? And why is it effective to put it in here? But even with all of the amazing innovation that’s happening in machine learning
and deep learning right now, there’s a lot that you can do without artificial neural networks. A lot of simple, fun exercises and things. So in this particular session, session three, I’m gonna look at the other algorithms that are non-artificial neural network– non-neural network based that
become the machine learning recipe, like K nearest neighbor. But let’s take a moment here to talk about how overall this works, because the thing is this doesn’t just happen magically. You can’t just– The point of doing this is that at some day, we might want to put
an unknown image in here and get a classification label for that image. But how could a machine learning
recipe do that from nothing? And it can’t. So one of the things I wanna talk about here is how does this work. So before you can actually use machine learning to make predictions for unknown data, you need to train the system. So the training step involves– So there there are several different strategies for how a machine learning system can learn in order to perform operations like this. One is called supervised learning. And supervised learning is the strategy that I’m going to use in just about everything that I do in this particular course
from session three right now and on. Although, I will come back to
some other techniques as well. Another kind of learning is unsupervised learning. And another kind of learning that I really love, my favorite kind of learning, is reinforcement learning. In fact, I have a whole book
all about reinforcement learning that I’m reading right now. Okay, so what are these different– And, you know, there’s something
called semi-supervised learning and there’s little variations on this, but these are three core types of learning that can be applied to the machine learning process. Let’s start with reinforcement learning for a second. Reinforcement learning is the kind of learning where an agent observes the environment and chooses an action. You can think of a mouse trying to get through a maze. The mouse looks around.
There’s a wall here. There’s a wall here.
There’s a wall here. The mouse decides to go left,
or the mouse decides to go right. And then once the mouse makes that decision, the mouse receives a reward. And that could be a positive or negative reward. And as the mouse receives more positive rewards for certain kinds of actions, it does more
of those actions over the long term and gets better and better at things. So that’s reinforcement learning. I’m gonna spend a whole session
looking at this at some point, and we’re gonna see some techniques. I have an example that uses a kind of reinforcement-style learning to train– tp autonomously play the game Flappy Bird. Okay, unsupervised learning is a kind of learning that’s generally applied to data
that you know nothing about. So I have 100,000 songs, and I just want to kind of learn what patterns are there in the song. So typically, unsupervised learning is applied to problems like clustering. So I have all this data and I want to figure out how can this
data be arranged in groups? Could I have a–
And I don’t know anything about it. Could an algorithm figure out,
based on patterns in the data, how to group that data,
how to cluster that data? So I don’t know that this is something
that I’m gonna spend any time– It’s not on my current trajectory/syllabus, but it is something that I would like to do at some point in the future. I actually have some ideas for some stuff
I want to do about that eventually. Okay, but here we’re gonna
give a nice little star, and a heart, and a little smiley face,
and a little rainbow for supervised learning, because this is what I’m going to use in most of most of my examples
over the next several videos. The idea of supervised learning is I have training data. Training data. So number one, I have training data. Number two, I have test data. And number three, I have the rest of the world, a universe of data. So maybe we could call this unknown. Un– un– ah!
I can’t spell. Unknown data. So how does this work? So first, what we do in supervised learning is we take this training data. We have a huge database of– a spreadsheet of bedrooms, bathrooms, and square footage for houses with their actual price that they sold at. So we have a data set that has the parameters and some sort of target, often called a target. So this would be like the training data with the inputs
and a target. The idea is the inputs go into
the machine learning recipe, they come out the other side, and some sort of guess is made. Maybe the house actually sold for $1.5 million, but the guest was $1 million. Ah, so the machine learning recipe got it wrong. So we turn some knobs here,
and mess around with it to try to get it to have a better result that’s towards what that error– So we’re gonna talk a lot about
this error and that sort of thing. We’re gonna come back to this many, many times. So we do this over and over again
with lots and lots of training data, turning all the knobs,
trying to get it to do a good job. Then what we do is we have test data. Now, test data is just like the training data. It’s data that has inputs with a known result, a known result that we should get. But we didn’t actually use it while training, because we have this issue– a machine learning recipe might
perform really, really well with the training data,
but not with actual other data. So to see how well it’s working,
we’ve actually got to give it data that we didn’t use to train,
and that’s called the test data. So we would feed that, see how well it does, evaluate, and evaluate the performance, and say like, “Ah, you know what? “It got all the test data right.” It’s ready. It’s all grown up. Our machine learning recipe is ready to go, and we send it out into the world
to start interacting with unknown data. So this is really the process. This is supervised learning. It’s saying, “Hey, I’m the teacher.” This is the machine learning system. I’m going to teach the system
with my known data, with known output. I’m gonna test the data with separate
known inputs and known outputs, and then it’s gonna be all grown up. It’s gonna graduate. I’m gonna send it out into the world, and yadda, yadda, yadda. You know, more– By the way, I plan on doing a lot of
yadda, yadda, yadding neural network stuff. We might get to like, “And then you have to “do this calculus thing, yadda, yadda, yadda.” (laughs) So I think that’s a good practice
to yadda, yadda, yadda machine learning as much as possible. Okay, so that’s a brief introduction
to what machine learning is overall, and what some of the sort of key aspects
of how a machine learning system works. But we’re going to get into a lot more about the details here,
and we’re gonna look at a variety of different kinds
of recipes that can be put in here, and how they work with different kinds of data, like which recipe do you want to work with images, which recipe would you want for working with text, for this kind of classification,
for this kind of regression. But right now I’m going to move on
and start looking at nearest neighbor. What is this thing called nearest neighbor? How can I look at two different pieces of data? So let me– So I have a bunch of pre-made
examples in some of the– If you follow along with the playlist, you’re going to see a bunch of examples
where I code stuff from scratch. But I won’t be able to do– I’m not gonna do a video for
every single one of these examples. I mean, maybe I will someday. But the first thing I’m really
gonna start looking at is– and this is an example inspired by– this is an example inspired by Rebecca Fiebrink, who has a wonderful course called, I think, Machine Learning for Musicians and Artists from the company Kadenze– I’ll put a link to that in this video’s description– where she uses a tool that she built called Wekinator to do classification and regression
and a variety of other things. So she does a lot of stuff
with gestural interfaces and musical output. So one of the things I wanna look at– And I’m gonna hit play here. And what you’re gonna see is as I move the mouse near a particular note, the note changes. C, D, E, F. And this is actually a classification– This is an example of classification. What I’m doing is I have two-dimensional data, a Cartesian coordinate system, and I wanna classify every XY point
to a particular note. This is classification.
So the nearest note is the note that I play. I can actually switch this
example to perform regression, and this is an example now of regression. You can hear– I make a prediction based on a weighted distance. So here, I essentially have
an average of C and G. I’m hearing a little G. I’m at a frequency between G and C. You can hear G, C, G, C. So this is– these are the kind of examples that I wanna build to get you started
with understanding the algorithms and I have some ideas for some
creative possibilities that you can do. And then we’re gonna just keep going. So okay, so stay tuned. There’ll be a bunch of videos in this playlist where I go through a few
different examples and scenarios. I’ll come back with another video
with some homework ideas, and hopefully you’ll make
some stuff and share it with me, and live your life in this world/universe/place, and maybe give somebody a hug
or say something nice to somebody, ’cause those are good things to do, too. Okay, see you in a future video. (bell dings) (upbeat music)

44 thoughts on “3.1: Introduction to Session 3 – What is Machine Learning?

  • May 8, 2017 at 2:49 pm
    Permalink

    Notification Squad!!

    Reply
  • May 8, 2017 at 2:58 pm
    Permalink

    Hello 😀 from indonesia

    Reply
  • May 8, 2017 at 2:58 pm
    Permalink

    I was here before it gone viral :v

    Reply
  • May 8, 2017 at 3:10 pm
    Permalink

    I was the 199th viewer. you owe me10 bucks

    Reply
  • May 8, 2017 at 3:13 pm
    Permalink

    Until the computer turns against you xD

    Reply
  • May 8, 2017 at 3:25 pm
    Permalink

    Your book just arrived to me today, excited to read it 🙂

    Reply
  • May 8, 2017 at 3:37 pm
    Permalink

    5:42 autocorrection kicked in

    Reply
  • May 8, 2017 at 3:40 pm
    Permalink

    FINALLY. This is my job, I work on these for years. And you got no idea how good it will feel to actually hear someone else talk about it with your personality. LET IT BEGIN!

    Reply
  • May 8, 2017 at 4:17 pm
    Permalink

    Damn … My favorite topic !!!

    Reply
  • May 8, 2017 at 4:25 pm
    Permalink

    Pls never stop making videos, they are truly amazing <3

    Reply
  • May 8, 2017 at 5:01 pm
    Permalink

    You do your tutorial in p5, but do you recommend beginner to apply your lesson directly to p5?

    Reply
  • May 8, 2017 at 6:14 pm
    Permalink

    Hi, i have a problem with my code, that i created using the videos before. I have created a tree and a rain. It works, but it is slow. The problem is i do not want to draw the tree every time, but when i put it in setup function it does not work.
    Code:
    var rainDrops = [];

    function setup() {
    createCanvas(displayWidth, displayHeight);
    background(51);

    for (var i = 0; i < 500; i++)
    rainDrops.push(new RainDrop());
    }

    function draw() {
    //Tree //<– <– The code here marked as tree in draw, is the code, that i want be drew only once
    background(51);
    stroke(255);
    translate(width / 2, height);
    createTree(200);
    //Rain
    for (var i = 0; i < rainDrops.length; i++) {
    rainDrops[i].fall();
    rainDrops[i].show();
    //Sets the y value back
    if (rainDrops[i].y > height) {
    rainDrops[i].y = random(-2000, -1000);
    rainDrops[i].ySpeed = random(5, 10);
    }
    }
    }

    //Creates one raindrop
    function RainDrop() {
    this.x = random(-width, width);
    this.y = random(-2000, 1000);
    this.ySpeed = random(5, 10);
    this.len = random(5, 15);

    this.fall = function() {
    this.y += this.ySpeed;
    this.ySpeed += 0.05;
    }

    this.show = function() {
    //stroke(50, 100, 250);
    stroke(255);
    line(this.x, this.y, this.x, this.y + this.len);
    }
    }

    //Creates fractal tree
    function createTree(len){
    var angle = PI / 8;
    line(0, 0, 0, -len); // Trunk
    translate(0, -len);

    //Branches
    if (len > 5) {
    push();
    rotate(angle);
    createTree(len * (2 / 3));
    pop();
    push();
    rotate(-angle);
    createTree(len * (2 / 3));
    pop();
    }
    }

    Reply
  • May 8, 2017 at 9:14 pm
    Permalink

    What to learn first processing or p5?

    Reply
  • May 8, 2017 at 10:22 pm
    Permalink

    Great presentation and introduction to the complex concepts of Machine Learning. Finally, everything seems easy now! Thank you Mr. Shiffman

    Reply
  • May 9, 2017 at 1:31 am
    Permalink

    You are just amazing, Dan. I remember I asked on a live if you could teach us about machine learning, you said that it would be a little complicated in coding challenges – I thought you would never talk about this wonderful world of ML – but I misunderstood you – then you started this GREAT series. thank you.

    Reply
  • May 9, 2017 at 4:50 am
    Permalink

    Now you won a new subscriber. Nice video man

    Reply
  • May 9, 2017 at 4:11 pm
    Permalink

    I am WebDeveloper and 1 problem I have with Machine learning is, I don't know how to use this kind of technology with javascript node.js angular 4, can you show one example how to use machine learning or A.I with this programming languages

    Reply
  • May 9, 2017 at 8:05 pm
    Permalink

    why don't you put genetic algorithms below reinforcement learning? 🤔

    Reply
  • May 12, 2017 at 11:33 pm
    Permalink

    hello! looking through andrew ng's courses too! 🙂

    Reply
  • June 14, 2017 at 4:02 pm
    Permalink

    can u plz teach JavaScript complete in just one video

    Reply
  • June 29, 2017 at 8:03 am
    Permalink

    Thanks for making this world a better place. I like the philosophy and energy with which you live always happy and just goofy. I want to grow up and be like you too. You're one of my hero now. 🙂

    Reply
  • July 6, 2017 at 5:59 pm
    Permalink

    thank you teacher

    Reply
  • October 23, 2017 at 4:14 am
    Permalink

    Excelent videos, thanks for your help. I hope you make more about machine learning and AI. is have some time maybe you can make videos about python .

    Reply
  • January 20, 2018 at 2:48 pm
    Permalink

    Daniel. I have a request. I'd like to see a step-by-step tutorial on Reinforcement learning in Processing from start to end. Maybe like the AI solving a labyrint or similiar.
    I've searched the web for hours but cannot find a single good tutorial that goes through the process from start to end without tons of dependencies that won't work for us windows users.

    Reply
  • February 1, 2018 at 7:26 pm
    Permalink

    You Sir are aweosme!

    Reply
  • March 10, 2018 at 10:13 pm
    Permalink

    So sad you have not too many videos on ML, tensorflow and similar stuff. You are a good educator and I think the only one on youtube who can give an adequate explanation on this topic = (((

    Reply
  • March 25, 2018 at 6:21 am
    Permalink

    I came here while doing andrew Ng ML course to find supplement material to understand technical terms and the stuff which he skips over there lol even here it is termed as yada yada yadaa. but i find you very interesting 🙂 I'll continue refer both for greater understanding. (I have just taken a baby step in the world of ML )

    Reply
  • March 28, 2018 at 10:15 pm
    Permalink

    man, I wish you were my teacher ; good thing I found you now at least 🙂

    Reply
  • May 7, 2018 at 3:02 pm
    Permalink

    And you’ve finally done the Flappy Bird neuro evolution 1 year later !

    Reply
  • June 7, 2018 at 11:13 am
    Permalink

    actually dan, it's kind of a standard now, while building a binary classifier, to label your output options as 'hotdog' and.. 'not hotdog'. ^_^
    https://www.youtube.com/watch?v=ACmydtFDTGs

    Reply
  • July 2, 2018 at 7:37 pm
    Permalink

    You are awesome!!!

    Reply
  • July 3, 2018 at 3:49 pm
    Permalink

    You are awesome bro..
    Have u made video on Support Vector Machine?? If yes . may I know the Playlist name

    Reply
  • August 28, 2018 at 11:55 am
    Permalink

    I agree with your pronunciation of the word data 🙂

    Reply
  • November 7, 2018 at 4:36 am
    Permalink

    Dan told me to hug someone so I'm gonna hug someone.

    Reply
  • November 25, 2018 at 11:13 pm
    Permalink

    can we classify hidden markov model as a machine learning recipe ?

    Reply
  • January 13, 2019 at 9:18 pm
    Permalink

    @18:00 stay tuned :'D pun master!

    Reply
  • March 5, 2019 at 12:47 am
    Permalink

    You are the best, please make video on RL with JS

    Reply
  • March 5, 2019 at 2:04 am
    Permalink

    i luv u

    Reply
  • April 5, 2019 at 10:21 am
    Permalink

    Thanks for your videos. Your positivity is contagious 🙂

    Reply
  • April 11, 2019 at 6:07 pm
    Permalink

    It hurts my OCD to not have the ending double quote on dog. 6:58

    Reply
  • June 12, 2019 at 5:31 pm
    Permalink

    Your explanation is great. ML, DL, RL with python language please……

    Reply

Leave a Reply

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