Chapter Objectives
• To understand the process of implementation of the artificial neural network (ANN).
• To understand the role of keras and its different modules in building the ANN.
• To understand the syntax for adding input layer, hidden layers, and output layer to ANN.
• To perform a compilation of the ANN model.
• To fit the ANN model on the training dataset.
• To make predictions with a trained ANN model.
• To evaluate the performance of the ANN classifier by using confusion matrix, precision, and recall.
17.1 Building Artificial Neural Network for Cancer Detection
Machine learning (ML) can play a crucial role in cancer detection. In this chapter, we will build a neural network for cancer detection by using a breast cancer dataset.
You can download this dataset by using the following link.
https://www.kaggle.com/datasets/uciml/breast-cancer-wisconsin-data
The acquired data contains the records of cancer patients in the United States. These records were created by Dr William H. Wolberg and others at the University of Wisconsin, USA. The whole data has 32 columns along with 569 rows. The prominent attributes are the radius, texture, perimeter, smoothness, concavity, symmetry, area, compactness, concave points, and the fractal dimension of the tumor. A snapshot of the dataset is depicted in Figure 17.1.
The dataset has a diagnosis column used as an output variable, while the remaining variables will be used as input data. The class attribute diagnosis has two classes, i.e., malignant identified as M and benign identified as B. Thus, it will be a binary classifier.
The code and dataset used in this chapter are also available at the following link.
https://github.com/bhatiaparteek/ml_with_python/tree/main/Chapter_17_ANN
To build ANN over this dataset, the whole procedure can be divided into three sub-parts below.
i. Loading the dataset and performing pre-processing of data
ii. Building the artificial neural network (ANN)
iii. Making predictions and performing the validations
Let us perform all these operations by following a step-by-step approach.
17.2 Loading the Dataset and Pre-processing
In this step, we will perform tasks of loading the dataset and pre-processing.
17.2.1 Step 1: Importing the Libraries
To perform this task, we need to import two libraries, i.e., Pandas and NumPy, as shown in code snippet 1. NumPy facilitates mathematical operations, while Pandas specializes in loading and extracting datasets.