Hello and welcome to this art tutorial.
So we just connect it to our H2O instance and now things are going to get easy.
That's another reason why.
This H2O package is great.
Because in a few lines of code, we're going to be able to build a complex
deep learning model. And this will be very simple.
We'll just use one function and then input different parameters.
I'm going to first define our classifier that I call classifier then equals.
Then that's. Where we use the H2O. Function.
So to take this function we need to take.
First the H2O package.
And then the function that we're going to use
right now is one of the functions here.
And you are
going to like the name of this function since it is called deep learning.
So that here.
And then. Deep.
And here it is deep learning.
That's the function we'll.
Use to build. Our deep learning model.
Pressing enter and here we go.
Now we just need to input the different arguments.
So what I'm going to do now.
Is go here. And press F1.
To have a better look at all the.
Arguments. Of this H2O.
Deep learning function.
So let's see.
Let's scroll down here to find the arguments.
And here we go.
So the first argument is x vector containing the character
names of the predictors in the model.
That's actually not a required argument.
We don't need to input it.
So we'll move on to the next one.
So the next one is y.
The name of the response variable in the model.
So we will have.
To use this one because actually the next argument is training frame.
And this training frame argument is.
Basically the. Training set.
That means that for this training frame argument will input our training set here.
And since the training set contains both the independent variables
and the dependent variable, we need to.
Specify with this y.
Argument here, what is the dependent variable in this training frame.
That is our training set.
And so with these two informations training frame and y
the model will then understand what is the training set.
What are the independent variables and what is the dependent variable.
So let's start.
By inputting these two arguments.
First y equals.
And as you can see it is just asking for the name of the response variable.
That is the dependent variable.
So here we just need to.
Input in quotes the name of the dependent variable.
Which is exited.
All right done for the first argument comma.
And then moving on to the second argument.
So the second argument is training underscore frame.
Here we go.
And so that's our training set.
And therefore we input here training set.
All right.
But now be. Careful because as it is said.
In this training frame argument info here.
This is an H2O frame object.
And right now our training set is not an H2O frame object.
It is just. A training set.
That is a data frame.
But that's not an H2O frame.
So we need to convert.
This.
Data frame training set into an H2O frame.
And to do this, there is one very simple way.
It is to use the as dot h2o.
Function.
That is a function that will convert its input here training
set that so far as a data frame into a H2O frame,
and therefore this training frame argument is getting what it is expecting.
Great.
Second argument done come up.
Moving on to the third argument.
So what is the third argument now?
Well, we have other arguments like model ID but we won't use it.
Overwrite. With best models.
So that's some other options.
But let's not focus on that right now.
That's not the most important.
Then simple validation frame checkpoints autoencoder pre-trained autoencoder.
So that's again not the most important.
But then moving on to what's most important.
We get to.
Activation, which of course corresponds
to the activation function you want to use for your network.
And so that argument is very important because you saw an intuition
tutorial that some activation functions are better than others.
And actually, as Kirill explained,
the best activation function to use to train an artificial neural network
is the rectifier function, which is this function here on this slide.
And that's the function we'll use right now for artificial neural network.
All right. So let's input activation.
Equals.
And then in quotes. Rectifier.
Make sure to type capital R.
So perfect we have one of the best choices of.
Activation functions for artificial neural network okay great.
And then come up moving on to the fourth argument.
So the fourth argument is actually the one just.
Below. Hidden.
And that's the hidden layer sizes.
That is it's a. Two and one argument.
Because specifying this argument.
Will allow you to specify.
Two parameters of your network at the same time.
The first parameter is the number of hidden layers,
and the second parameter is the number of nodes in each hidden layer.
And so how do we input.
These two.
Parameters in this only one argument here?
Well, we are doing this with a vector.
The number of elements of this vector will be the number of hidden layers,
and the value of each element of this vector will be the number of nodes
in the hidden layer.
So for example here we have c.
So you know C is the way. To define a vector in R.
Then first element of the vector 100
and then second element of the vector 100 again.
So that means that here
we have a vector of two elements and therefore will have two hidden layers.
And in the first hidden layer will have 100 neurons,
and in the second hidden layer will have 100 neurons.
Again.
And now time to ask ourselves a big question,
a question that comes very often when building a deep learning model.
It's how many layers do we want to choose?
That is, how many elements in this vector,
and then how many neurons we want to put in each layer.
So unfortunately, the bad news is that there is no rule of thumb to.
Choose this. Optimal number of hidden layers.
And these optimal numbers of neurons in the hidden layers.
But there is a tip. That we can use.
And this tip is not really based on research, but rather based on experiments.
We observed that.
A convenient choice. Of.
Number of hidden nodes in the hidden layers not the optimal choice.
But. More. A convenient choice.
Is to have the average.
Of the number of input nodes and the number of output nodes.
And as you saw in Carol's intuition tutorial, well, the number of input nodes
in the input layer.
Is. The number of independent variables.
So the number of input nodes in the input layer is ten.
Because we have ten independent variables,
and the number of output node in the output layer is one.
Because again, you saw in Carol's intuition tutorial,
that's when our dependent variable has a binary outcome.
Well, there is only one output node in the output layer.
So that means that the number of neurons will choose in the hidden layer
is going to be ten plus one divided by two.
That is 5.5.
But of course we need to take a round number.
So we'll go for six.
Six neurons in the hidden layer.
And so now to be honest we are not working with some complex data.
Set like for.
Example images to find some patterns in the pixels.
Here we have a simple data. Set with.
Some independent variables and one dependent variable.
And there is no spatial structure in this.
Data set like. It is the case for images.
So to be.
Honest, we don't need many hidden layers.
In fact, I'm pretty sure our Ann and model.
Would work very well.
With only one hidden layer.
But hey, since we are in the deep learning part.
Let's go for. Two hidden layers.
That will not be this kind of deep learning model.
But that will be a start.
All right, so let's input these layers.
With the neurons inside.
So I'm going to add the hidden argument.
Here we go.
And so as you understood we need to.
Specify.
These numbers of layers and these numbers of neurons in the layers.
With a vector. So c parenthesis.
Then the first element of this vector
is the number of neurons in the first hidden layer.
So we said six.
Then comma and then the second element of this vector
is the number of neurons in the second hidden layer.
And so let's. Pick six as well.
Keep in mind that in part ten we will be able to improve.
These choices.
Of parameters thanks to parameter tuning techniques.
Like k fold cross-validation.
But for now.
Let's just focus. On deep learning.
Okay good.
So that's it for this hidden argument.
And so now let's move on to the next argument.
The next argument is going to be the one just below hidden.
That is epochs.
So that is of course.
The number of epochs in the stochastic gradient descent algorithm.
We actually have a. Good description. Here.
The number of epochs. Is. How many times.
The data set should be iterated.
If we go back to.
Our intuition, slide about this stochastic gradient descent algorithm,
well, we can see this number of epochs here in step seven,
when the whole training set completed all the steps from one to. Six.
Passing through the A and then
well that makes an epoch and we redo many more epochs.
So this number of. Epochs here is.
This number of times we are repeating the whole process of steps one to.
Six for the.
Whole training set, either by updating the weights.
After each observation.
Or validating the.
Weights after each batch. Of observations.
For example, ten observations.
So let's add this epochs argument here.
Here we go.
And as in Python we are going to input 100 epochs.
Great.
And now we have one final argument to input.
That is.
Actually the one just below.
Again train samples per iteration.
So what is that you might have guessed. What it is.
Well first the.
Description says that it's the number of training samples per MapReduce iteration.
But more simply that. Is your batch size.
That is the number of observations after which you want to update the weights.
So this number can be one.
If you want to. Update the weights after each observation.
Passing through the A and N, and in that case that's called reinforcement learning.
Exactly as we saw in part six, reinforcement learning
or this number can be more than one.
That is for example, when the weights are updated after.
Each.
Batch of ten observations passing through the end.
And in that case that is called batch learning.
Okay. So let's input this argument.
Train symbols per iteration.
Here it is pressing enter.
And now the good thing is that we don't even need to choose.
A batch size.
Because as you can see we.
Have these three parameters zero.
Minus one and minus two.
And as you can. See.
This minus two.
Value is very practical because by.
Specifying minus two here, this will autotune your artificial neural network.
And that corresponds to the third reason why. H2O.
Was to me one of the. Best packages.
It's because it gives you the.
Option to already apply some parameter tuning.
Parameter tuning can be way more.
Complicated, but here we have this great tool that will already help.
Us to improve the model.
So let's definitely input minus two here.
And actually now artificial neural network is ready.
That's all the parameters we need. To build.
Our artificial neural network.
And we even have some parameter tuning.
So we have. Everything we need and even more than we need.
Therefore let's do it.
I'm going.
To select all. These lines here.
That will create the. Classifier.
And now I just want to say something important for.
Those of you who follow the. Python tutorials.
Well you saw that. Training DNN took quite.
A while.
It took about.
One minute, if I remember correctly, and that was.
Because we used our CPU on our system.
But here we are connected to a server, and so we have access to a powerful.
System using this. H2O. Instance.
And therefore. You will see how.
The model is going to be trained much faster.
We are going to see that right now I'm going to execute.
Ready. Three two. One. Go.
And that's it.
That's already ready.
It took about five seconds.
So that's pretty exciting.
To work. With such powerful tools.
I was very happy to show you this.
And I hope that now you're convinced.
That with this H2O package you are.
In good hands. So great.
And now that our model is trained,
time for the next step making predictions on the test set.
And that will be very interesting to do.
To see the accuracy on new.
Observations on which the model wasn't trained.
So we'll see that in the next tutorial.
And until then, enjoy machine learning.