Artificial Intelligence (AI) is growing exponentially. There is no doubt about that. Self-driving cars are clocking up millions of miles, IBM Watson is diagnosing patients better than armies of doctors and Google Deepmind’s AlphaGo beat the World champion at Go. This is a game where intuition plays a key role.
But the more AI advances, the more complex the problems become that it needs to solve and only Deep Learning can solve such complex problems. That’s why it’s at the heart of Artificial intelligence.
Deep Learning refers to training a system which is capable of learning and imitating human behavior. It works with large volumes of (both structured and unstructured) data, and uses complex algorithms to train a model. Neural networks help to implement Deep Learning.
Deep learning is gaining popularity because of two factors. First of all, because we have large amounts of data available to train the program. The second factor is due to the technological advances in storage devices and increased computation power with the advances of GPU and TPU.
There are two approaches to make a program do some useful task. The first is rule-based and the second is an AI-based approach.
- Rule-based Approach: In this approach, we code the program and guide it all the way to achieve something by covering all the possible scenarios.
- AI-Based (neural network): Here, we create a facility for the program to understand what it needs to do on its own. So, basically, in a neural network we provide input and tell what we want in the result and the neural networks can figure out the rest on its own.
A neural network mostly consists of 3 layers: input, hidden and output. Each layer consists of neurons (also called nodes) that perform numerical computations and other operations.
- Input layer: The input nodes provide information from the outside world to the network and are together referred to as the “input layer”. No computation is performed in any of the input nodes, they just pass on the information to the hidden nodes.
- Hidden layer: The hidden nodes have no direct connection with the outside world (hence the name “hidden”). They perform computations and transfer information from the input nodes to the output nodes. A collection of hidden nodes forms a “hidden layer”. While a feed forward network will only have a single input layer and a single output layer, it can have zero or multiple hidden layers.
- Output layer – The output nodes are collectively referred to as the “output layer” and are responsible for computations and transferring information from the network to the outside world.
Below, I’ve stated some important terms used in neural networks:
- Cost function: They are used to estimate how badly models are performing, this is typically expressed as a difference or distance between the predicted value and the actual value. Our goal is to minimize the cost function.
- Activation function: The activation function of a node that defines the output of that node given an input or set of inputs. This output is then used as input for the next node and so, on until a desired solution to the original problem is found.
Building an artificial neural network for a bank
- Setting up an Integrated Development Environment (IDE) and installing libraries: There are many IDEs available for development of AI models but Anaconda is the most preferred due to its easy to use environment and library support for data science.
Installation is quite similar in all operating systems (Windows, Linux and Mac).
- Visit the below link to download the installer and choose Python 3.x version https://www.anaconda.com/download/
- Install it and launch the Anaconda Navigator
- From the Anaconda Navigator Launch Spyder the IDE which we will be using for this blog.
Installing the Libraries
- Installing TensorFlow: Open Source numeric computation libraries are very efficient for fast numerical computation based on NumPy syntax. It can be used in CPU, GPU, and TPU
- Installing Keras: This is an amazing library which is based on TensorFlow and we will be using this to build deep learning models very efficiently
- Pandas: Pandas is an open source, BSD-licensed library which provides high-performance, easy-to-use data structures and data analysis tools for the Python programming language) (pre-installed)
- NumPy (NumPy is the fundamental package for scientific computing with Python) (pre-installed)
Next, open the command prompt and run the following commands:
- Conda install TensorFlow
- Conda install Keras
A bank has given you the data of its customers and wants you to make a model which will predict whether a customer will leave the bank or not, so that they can take some steps/actions to retain their customers. You can find the attached the .csv file and a snapshot of the data below.
As we can see there are n number of features in the dataset. So, it is hard to find out which feature contribute how much to the result so, artificial neural network comes to the rescue. Provide the model with a huge amount of data, it will learn and do the job for you.
Open a new file in Spyder and run the following code:
Part 1 – Data Preprocessing: This step is applicable and common to all machine learning algorithms and it includes importing the data set, encoding the categorical variables, avoiding dummy variable trap and Feature scaling.
Part 2 – Building the artificial neural network – This step includes using the Keras model to create a classifier and add 1 input, 2 hidden and 1 output layer to the model.
Please have patience while training the model as it may take up some time depending on your CPU, GPU, and TGU.
We have got an accuracy of 85.23% in this model. We can improve it further by tweaking the code and training it by feeding the AI with more data. (This is always a scope to improve 😊)
So, that was my experience on training my first artificial neural network. Please do visit my GitHub page for the complete code. https://github.com/rajatg64/Machine-Learning.
Please comment down for any suggestions and improvement (Happy Coding).