Using ANNs to Diagnose Cancerous Tumours

I decided to start living a more intentional and productive life as I don’t want to face any sort of mid-life crisis and I want to be happier carrying out my passion for technology throughout life.

I’ve been interested in deep learning recently and decided to enroll myself into a Udemy course so I can expand on my knowledge and learn from some experts through the internet.

Hands down this is the best decision I’ve made in 2019 so far! I enrolled in a course called “Deep Learning A-Z” which goes over most of what there is in deep learning in some good detail.

The course itself has a section for artificial neural networks (ANNs) which is rich in content, but the course was only teaching me how I could use ANNs for business problems. BORING!

I took what I learned from the Udemy course, made my own template and decided to try and tackle one of the issues with our current tumour diagnosing process.

If your reaction to this is “what in the world is an artificial neur-” Shhhh, go read my last article!

Well to briefly explain, artificial neural networks are made up of layers of programmed neurons that are loosely modeled off of our brains neurons. This is so that machines can make logical predictions and behave sort of like how our brains work.

The problem with the current system is that doctors generally detect tumours at stage 3 or 4 cancer, which is really late! Chemotherapy may be “old fashioned” but it’s proven to be effective when used on early stage cancer. Currently, by the time the tumours are detected, the patient is already highly likely to die.

Humans can’t recognize small patterns that are signs of tumour growth because we don’t know all of the information that is relevant to diagnosing a tumour as cancerous or not. Machines can recognize small overlooked patterns and can produce a more accurate output than humans can.

SO WHY AREN’T WE USING THEM?

I decided that instead of sitting around talking about implementing AI into cancer detection, I should go out and build it myself because I know I can.

Coding the ANN

I started off by downloading a breast cancer tumour dataset, which included 29 different features that were connected to each tumour in the dataset. All the tumours were already classified as malignant or benign so that I could use them for training my ANN.

Before I started building the ANN, I needed to perform data preprocessing. Data preprocessing is when the dataset is being prepared to be fed through the ANN later. I then imported any necessary libraries and I organized the dataset into which arrays are inputs and which are outputs.

Next, according to my template, I would take care of missing data but in my dataset there was none, so I left it commented out. Then, I was required to encode any categorical data I had, in my dataset, only my output variable (if the tumour was malignant or benign) needed to be encoded (as a value of 1 or 0) as the computer recognizes numbers, not words.

After that, I split the dataset into training and test sets. The ANN would train itself to make predictions on the training set and it would then be tested to see how accurate it can be when making predictions with inputs it’s never seen before. I used 20% of the data I had for the test set and 80% for the training set. Next, I was required to use feature scaling because the values of the inputs were all over the place, and if I wanted to represent these on a graph to find correlation between them, I needed them to all be a part of the same scale (between 0 and 1).

I started by importing the required Keras libraries and initializing the architecture of the ANN to be sequential. Which means that I want to stack all of my layers, one on top of the other, sandwiching them and creating the ANNs structure.

Then I began to add each layer. I started with the input layer, which I programmed to pump out 15 outputs, using 29 input features and a rectified linear activation function.

For the second layer, I didn’t need to add input nodes because the structure of the network is set to be feed forward, which means the outputs from one layer are used as the inputs for the next layer. I again set 15 outputs and used a rectified linear activation function.

For the last layer, (again, the layer expects 15 inputs from the last layer so I don’t need to code it in) I set the output to 1 because I only want 1 output, whether the tumour is cancerous or not. This time, I used a sigmoid function so that I can get a prediction between 0 and 1 and not just a value equal to 0 or 1. This is so I can evaluate how confident the ANN is with it’s prediction. We then compiled the ANN and had it display the loss and accuracy of the network.

We’ve come to the step we’ve finally been waiting for. I set 100 epochs to train the ANN using the 80% of training data we have. 1 epoch is when the entire training dataset is back propagated through the whole network once. Back propagation is when the dataset is fed through the network, pumps out a response, checks if the predicted response matches the actual response, then feeds the data backwards and adjusts all the weights to achieve a higher level of accuracy.

Now that we’ve trained the ANN, we can test is using the 20% test data we have left. Remember we encoded the outputs from the data set to be either a 0 or 1, now, we need to convert the number we get from the last layers sigmoid function, into a prediction. In the code, I established that the tumour is malignant if the out put is greater than 0.5 and benign if the tumour is less than that value.

Lastly we’re going to make a prediction matrix, which will show us the number of correct predictions vs the number of incorrect predictions for both malignant and benign tumour classifications.

Now What?

Now that you know how I built my very own tumour classifier, what’s the significance of this? Well we know that cancer is a problem and that we haven’t found the cure to it yet, but we have the technology to tackle this problem in a different way, by detecting it earlier, so why hasn’t anyone used it!?

According to to a study conducted by Novigenix in December of 2018, patients diagnosed with stage 1 or 2 cancer (before symptoms) have a 90% chance of living for the next five years, but patients that are diagnosed (after symptoms) with stage 3 or 4 cancer only have a 10% chance to live!!

Symptoms generally show up around stage 3 or 4 which is when doctors can more easily diagnose cancer because the doubt of a tumour being present comes up; during stage 1 or 2 cancer however, symptoms are not as common and are mostly over looked even by doctors.

Machines however though, can detect cancerous cell growth as they can make correlations from even small amounts of data (assuming it’s already been trained very well to being with).

According to Cancer Research UK, 1 in 2 people will be diagnosed with cancer in their lifetimes! WHICH IS INSANE!

Looking Into The Future

We need more smart people to push the boundaries of AI and implement it into our healthcare system as it’s proven to be more accurate and reliable then conventional ways of diagnosis. People are scared that AI in healthcare will replace doctors, but I believe that AI will aid doctors to provide better treatment, not replace them (not for a long time that is).

If people recognize the potential of AI in the heathcare system and change is made, I can imagine communities having small clinics set up where anyone can walk in with a small sample of cells, get checked up and detect cancerous cells early.

AI is going to aid us heavily when it comes to solving the worlds leading cause of death using a new approach. We have treatment that works but our detection methods are currently faulty. So why don’t we slow down on throwing billions of dollars towards “researching a cure for cancer” and start working with what we have to dramatically decrease fatalities from cancer!?

Hey you made it to the end! Thank you for reading my article, if you enjoyed the read, please clap and comment any feedback you have below. If you want to reach out to me, you can connect with me through LinkedIn (Manpreet Shergill) or my email rkgill@live.ca.

Machine Learning Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store