Implementation of Binary Classification

Tinkal Shakya
3 min readJun 16, 2021

--

What is Binary Classification?

Binary classification means that there are two classes to work with which are related to each other namely true and false.

For Examples :

  • Email spam detection (spam or not).
  • Churn prediction (churn or not).
  • Conversion prediction (buy or not).

In binary classification, one class is the normal state and another class is the abnormal state for example, “not spam” is the normal state and “spam” is the abnormal state.

You have divided your data into training and test sets and used the training set to train your model.

Not all test set rows classified as ‘negative’ by the model will actually be ‘negative’. The same applies to ‘positive’. that means. This is where a confusion matrix comes into play.

What is Confusion Metrix?

The confusion matrix is a technique for summarizing the performance of a classification algorithm. A Confusion matrix is used to n*n matrix of a classification model. The matrix compares the actual target values predicted by the machine learning model. and read more to click here

Using Dataset

The data set we will be using for this example is the very popular “Churn prediction” dataset. In this dataset, we have predict the customer are exist or not in the company.

scikit-learn provides the tools to pre-process the dataset, The data set in this format.

Build Model

In this model, First, we have import the pandas library. and load the dataset in a variable and after that split the data into train and test data. we have also preprocessing the data. and covert the data string format into the numeric format.

Create the layers using the Dense function. and also add the neurons. In this Dense function, the units define the number of neurons. and use the activation relu (The function returns 0 or 1 if it receives any negative input, but for any positive value x it returns that value back.) and we have also use initialize the kernel size and bias is “zeros” and if we should not initialize the kernel size and bias. it by default set the “glorotUniform initializer”.

In the output layer, we have used the sigmoid function as the activation function. sigmoid is used as the activation function for binary classification problems. sigmoid is especially used for models where we have to predict the probability as an output. Since the probability of anything exists only between the range of 0 and 1

In this model, we have to use Adam optimizer. and also use the learning rate. Adam Optimizers are used to change the weights and learning rate in order to reduce the losses.

This graph shows the accuracy and loss of the model.

GitHub repository — https://bit.ly/3xsqDC0

--

--

Tinkal Shakya

Senior Cloud Engineer at Cloudside Technologies Pvt Ltd || DevOps Engineer || MlOps Engineer