Nothing but NumPy: Understanding & Creating Binary Classification Neural Networks with Computational Graphs from Scratch
By: Rafay Khan
Tags: Numpy, AI, Neural Networks, Data Science, Machine Learning

Nothing but Numpy is a continuation of my neural network series. To view the previous blog in this series or for a refresher on neural networks you may click here.

This post continues from Understanding and Creating Neural Networks with Computational Graphs from Scratch.

It’s easy to feel lost when you have twenty browser tabs open trying to understand a complex concept and most of the writeups you come across regurgitate the same shallow explanations. In this second installment of Nothing but NumPy, I’ll again strive to give the reader a deeper understanding of neural networks as we delve deeper into a specific kind of neural network called a “Binary Classification Neural Network”. If you’ve read my previous post then this will seem very familiar.

Understanding “Binary Classification” will help us lay down major concepts that help us understand many of the choices we make in multi-classification, which is why this post will also serve as a prelude to “Understanding & Creating Softmax Layer with Computational Graphs from Scratch”.

This blog post is divided into two parts, the first part will be understanding the basics of a Binary Classification Neural Network and the second part will comprise the code for implementing everything learned from the first part.

Part Ⅰ: Understanding Binary Classification

Let’s dig in🍽️

Binary classification is a common machine learning task. It involves predicting whether a given example is part of one class or the other. The two classes can be arbitrarily assigned either a “0” or a “1” for mathematical representation, but more commonly the object/class of interest is assigned a “1”(positive label) and the rest a “0”(negative label). For example:

Is the given picture of a cat( 1 ) or not-a-cat( 0 )?

) or not-a-cat( )? Given a patient’s test results, is the tumor benign( 0 ; harmless) or malignant( 1 ; harmful)?

; harmless) or malignant( ; harmful)? Given a person’s information (eg. age, education level, marital status, etc) as features, predict whether they make less than $50K( 0 ) or more than $50K( 1 ) a year.

) or more than $50K( ) a year. Is the given email spam(1) or not-spam(0)?

In all the examples above the object/class of interest is assigned a positive label(1).

Most of the time it will be fairly obvious whether a given machine learning problem requires binary classification or not. A general rule of thumb is that binary classification helps us answer yes(1)/no(0) questions.

Now let’s build a simple 1-layer neural network(input and output layers only) and hand solve it to get a better picture. (we’ll make a neural network the same as the one elaborated in my previous post, but with one key difference, the output of the neural network is interpreted as a probability instead of a raw value).

Fig 1. Simple input-output only neural network

Let’s expand this neural network out to reveal its intricacies.

Fig 2. Expanded neural network

For those not familiar with all the different parts of a neural network I’ll go over each of them briefly. (A more detailed explanation is provided in my previous post)