Project implementation with ANN


Churn Modelling Problem

In this part, you'll be solving a knowledge analytics challenge for a bank. you'll tend a dataset with an outsized sample of the bank’s customers. To form this dataset, the bank gathered information like customer id, credit score, gender, age, tenure, balance, if the customer is active, features a master card , etc. During 6 months, the bank observed if these customers left or stayed within the bank.

Your goal is to form a man-made Neural Network which will predict, supported geo-demographic and transactional information given above, if a person customer will leave the bank or stay (customer churn). Besides, you're asked to rank all the purchasers of the bank, supporting their probability of leaving. to try to do that, you'll have to use the proper Deep Learning model, one that's supported by a probabilistic approach. If you achieve this project, you'll create significant added value to the bank. By applying your Deep Learning model the bank may significantly reduce customer churn.

Dataset sample:

Image for post

Part 1: Data Preprocessing

1.1 Import the Libraries


In this step, we import three Libraries in the Data Preprocessing part. A library may be a tool that you simply can use to form a selected job. First of all, we import the numpy library used for multidimensional array then import the pandas library wont to import the dataset and in last we import matplotlib library used for plotting the graph.

1.2 Import the dataset

In this step, we import the dataset to try to ensure that we use the pandas library. After importing our dataset we define our dependent and experimental variable . Our independent variables are 1 to 12 attributes as you'll see within the sample dataset which we call ‘X’ and dependent is our last attribute which we call ‘y’ here.


1.3 Encoding the Categorical data 

In this step, we Encode our categorical data. If we see our dataset then Geography & Gender attribute is in Text and that we Encode these two attributes during this part use the LabelEncoder and OneHOTEncoder from the Sklearn.processing library.



1.4 Split the dataset for test and train

In this step, we split our dataset into a test set and plaything and an 80% dataset split for training and therefore the remaining 20% for tests. Our dataset contains 10000 instances so 8000 data we train and 2000 for the test.


1.5 Feature Scaling Feature 

Scaling is the most vital part of data preprocessing. If we see our dataset then some attribute contains information in Numeric value some value very high and a few are very low if we see the age and estimated salary. This may cause some issues in our machinery model to unravel that problem. We set all values on an equivalent scale. There are two methods to unravel that problem: first one is Normalize and Second is Standard Scaler.
Here we use standard Scaler import from Sklearn Library:



Part 2: Building our Model
In this part, we model our Artificial Neural Network model.

2.1 Import the Libraries

In this step, we import the Library which can build our ANN model. We import Keras Library which can build a deep neural network supported Tensorflow because we use Tensorflow backhand. Here we import the 2 modules from Keras. The primary one is Sequential used for initializing our ANN model and therefore the second is Dense used for adding different layers of ANN.


2.2 Initialize our ANN model

 In this step, we initialize our Artificial Neural Network model to do that we use sequential modules.

2.3 Adding the input layer and first hidden layer 

In this step, we use the Dense model to feature a special layer. The parameter which we pass here first is output_dim=6 which defines hidden layer=6, the second parameter is init= uniform basically this is often a consistent function that randomly initializes the weights which are on the brink of 0 but not 0. The third parameter is activation= relu here within the first hidden layer we use relu activation. and therefore the last parameter which we pass in dense function is input_dim= 11 which suggests the input node of our Neural Network is 11 because our dataset has 11 attributes that’s why we elect 11 input nodes.


2.4 Adding the Second Hidden layer

In this step, we add another hidden layer.


2.5 Adding the output layer

In this step, we add an output layer in our ANN structure output_dim= 1 which suggests one output node. Here we use the sigmoid function because our target attribute features a binary class which is one or zero that’s why we use sigmoid activation function.

2.6 Compiling the ANN 

In this step, we compile the ANN to try to ensure that we use the compile method and add several parameters. The primary parameter is optimizer = Adam here uses the optimal number of weights. So for selecting the optimal number of weights, there are various algorithms of Stochastic Gradient Descent but very efficient one which is Adam so that’s why we use Adam optimizer here. The second parameter is loss; this corresponds to loss function; here we use binary_crossentropy because if we see a target attribute in our dataset which contains the binary value that’s why we elect the binary cross-entropy. The ultimate parameter is metrics basically It’s an inventory of metrics to be evaluated by the model and here we select the accuracy metrics.


2.7 Fitting the ANN

In this step we fit the training data: our model X_train, y_train is our training data. Here a batch size is essentially a variety of observations after which you would like to update the weights here we take batch size 10. and therefore the final parameter is epoch is essentially when the entire training set skilled the ANN here we elect the 100 number of the epoch.







        

Part 3: Making the Prediction and Accuracy Result. 

3.1 Predict the test set Result 

In this step, we predict our test set result here our prediction results in probability so we choose 1(customer leave the bank) if the probability is greater than one 0.5 otherwise 0(customer don’t leave the bank.)


3.2 Confusion metrics 

Now let’s make a confusion metric of our test set result to do that we import the confusion matrix from sklearn.metrics then in the confusion matrix, we are passing two parameters first is y_test which is the actual test set result and second is y_pred which predicted the result.


3.3 Accuracy Score 

Let’s calculate the accuracy score based on the actual test result and predict test results.


And finally... we get 84.05% of our ANN model.













Comments

Popular posts from this blog

Our First Workshop Went Like...!

Convolutional Neural Networks

Classification of Animals Using CNN Model