Hello my friends!
I'm super excited to start now.
A part of this course that we've been excitedly waiting for.
I'm talking, of course, about deep learning.
You just got the amazing intuition lectures by Kirill.
And so now you understand that what deep learning consists
of is building an artificial brain.
So there you go, my friends.
Now we're about to build an artificial brain using the brand new TensorFlow 2.0.
This will be super exciting.
We will really build a deep neural network with neurons
and fully connected layers connecting these neurons.
And we will apply all this to a business problem as usual.
And now that we are, you know, quite advanced.
And of course
the data set we'll be working on looks more like a real world
data set with many observations and many features.
And you will see that
we will actually have to not only use our data preprocessing template,
but also use some of the tools of our data preprocessing toolkit.
So are you ready?
Are you ready to go next level?
Indeed.
Now we're about to do some more advanced machine learning.
And so I'm super excited
that you're even pushing further your expertise in machine learning.
All right, so let's do this.
But first let's just make sure everyone here is on the same page.
So this is the folder of the whole machinery.
It is it with all the codes and data sets.
I gave you the link to this folder right before this tutorial.
So make sure to connect to it.
And now there we go.
Let's end to part eight Deep learning with
first the classic artificial neural network,
meaning the fully connected neural network with only fully connected layers.
You know, with no convolutional layers or other types of layers.
Here we will just have an input vector containing different features,
and we will predict an outcome which will be a binary variable,
because you have to know that actually artificial neural
networks can be both used for regression or classification.
And here we're going to do it for classification.
However note that we have a free course on artificial neural network,
in which this time we built an artificial neural network for regression.
So make sure to check it out.
I will think of including the links somewhere
so that you can get it as well, but it's really good.
You will have both cases.
You know, the classification case with this course and the regression case
with the other free course. All right.
So now as usual we're going to start with Python.
And there we go.
This folder contains the implementation first artificial neural network that ipynb
which you can either open with Jupyter notebook or Google Collaboratory.
And we have of course our data set, which I'm going to explain right now.
All right.
So as you can see,
as I told you, it looks indeed more like a real world data set, right?
For the first time.
Our data set takes the full screen here because indeed, this time
we have many features, you know, starting from here up to this one.
And the dependent variable right here.
All right.
So let me explain what this is about.
This is the data set of a bank
which collected some informations about their customers.
These informations are well row number.
That's just a non relevant feature.
We will get rid of it.
Then the customer ID.
That's just the identification key of each customer.
The surname, the credit score, the geography meaning the country,
the customer lives in, the gender, the age,
the tenure meaning the number of years that have been in the bank,
the balance meaning the amount of money they have on their account.
The number of products they use from the bank.
You know, like a credit card
or a checkbook or a Mastercard or even a loan or home loan.
You know, any banking products.
Okay.
So that's the number of products each customer has.
Then has credit card, yes or no, meaning that this variable is equal to one.
If the customer has a credit card and zero otherwise is active member,
meaning is the customer active, is he or she using the bank,
you know, connecting to its account or using its credit card or any other card?
You know, let's say
they have some measurement system to measure if a customer is active or not.
And one means,
of course, that the customer is active and zero means that it is an active.
Okay then estimated salary.
Well, you know, the salary of the customer estimated by the bank and that's it.
That's the last feature.
And then the last column here it is
the dependent variable and it tells if yes or no.
Well the customer stayed in the bank or left the bank.
One means that it left the bank as in exited equals yes.
And zero means that the customer stayed in the bank as an exit.
It equals no.
So what happened in reality is that this bank actually observed
their customers for a certain period of time, let's say six months.
They observed if during the six months they left the bank or stayed in the bank,
and they gathered these outcomes in this last dependent variable,
and at the same time, you know, they got all these features.
Well, to guess what, understand the correlations between these features
and the fact whether or not the customer stays in the bank or leave the bank.
And that makes sense, right?
Because a bank wants to have the maximum customers, right?
That's how they make money.
The more customers they have, the more they have money in the bank, and the more
they make money from the diverse products they offer to their customers.
So of course, their interest is to keep the maximum customers,
and therefore they made this data set to understand
the reasons somehow why customers leave the bank.
And mostly once they managed to build a predictive model
that can predict if any new customer leaves the bank.
You know, a model that was trained, of course, on this data set.
Well, they will deploy this model on new customers
and for all the customers, where the model predicts that
the customer leaves the bank, well, they will be prepared and they might do
some special offer to the customer so that it will stay in the bank, you see.
So all this is to prevent the maximum customers from leaving the bank.
And why is this girl churn modeling?
Because customer churn means exactly the situation
where some customers exit, you know, become no longer customer.
All right.
And of course, the bank has asked you the most down to data scientist
to make this predictive model, to first train it on this data
set to understand the correlations of all these features
and the dependent variable, and then to deploy this model on future customers.
And you will see that in the implementation, we will actually deploy
the future machine learning model will get on a different customer,
you know, not part of this data set, so as to predict
if this new customer will stay in the bank or leaves the bank.
And even better than this,
we will actually predict the probability that this customer leaves the bank.
So we have a lot to do ahead of us.
But I'm super excited
because deep learning is a fascinating branch of machine learning.
So let's start right away and let's open our implementation
artificial Neural Network dot Ipynb, which you can feel free to open
with either Google Collaboratory
as I'm about to do, or Jupyter Notebook as you want.
Just make sure you feel comfortable coding on your favorite IDE.
All right,
so now the implementation is opening laying it out the notebook.
Perfect.
That's the implementation once again in read only mode.
So right now we will click file here to create a copy of this implementation.
And as usual we will re-implement all this from scratch
so that we can really learn by doing.
All right.
So that's the copy.
Now let's remove all the cells right.
This one not the text cells of course, because we want to keep the well
highlighted structure of this implementation.
But let's definitely remove the code cells.
So there are many of them.
So you will actually have a bit of time doing it.
But you know it's not that long. It's fine.
There is a long data
preprocessing phase and then a long phase of building the neural network.
And I really gave the details of the implementation.
So you will actually see many steps.
All right.
And there are so many steps that I actually added a level of
structure because as you can see the full implementation is divided
into three parts. Right.
There is a homework at the end. The solution.
So let me not show it to you.
And that's almost the end confusion matrix and perfect.
All right okay so as you saw this is a long implementation.
This will be a long part.
But it is absolutely worth it.
Deep learning is one of the most powerful branches of machine learning okay.
So let's see.
We start first by importing the libraries as usual.
And then we enter part one data preprocessing.
So that's the first part of the whole implementation structured in four parts
which are the following parts one data preprocessing part
two building two and part three training,
and in part for making the predictions and evaluating the model.
And then each part well we have two different steps.
In part one data preprocessing we will first import the data set.
Of course then we'll have some data preprocessing to do.
You know, not only the classic steps of the template but also some extra tools.
And we will see that together.
Then in part two we will first initialize and then we'll add an input layer.
And the first hidden layer to our artificial brain.
Then we'll add the second hidden layer, then the output layer.
Then in the next part three training and we will first start
by compiling the CNN to, you know, an optimizer and a loss function.
Then we will train the CNN on the training set.
And finally in part four, well, we will deploy our model in production
to predict the result of a single observation, meaning
to predict if a new customer will stay or leave the bank,
then we will predict the test results to, you know, get that Y vector
to eventually make the confusion matrix with the final accuracy.
All right.
So once again as you can see this implementation is pretty long.
So make sure to have full energy and full motivation for this
because we have a long but yet exciting journey in front of us.
So as soon as you're ready,
well, meet me in the next tutorial to smash this implementation.
And until then, enjoy machine learning.