text: Breast Cancer Detection Using CNN
  Breast Cancer Detection Using CNN in Python
  Breast cancer is the most commonly occurring cancer in women and the second most common cancer overall. There were over 2 million new cases in 2018, making it a significant health problem in present days.
  The key challenge in
  breast cancer detection is to classify tumors as
  malignant or
  benign. Malignant refers to cancer cells that can invade and kill nearby tissue and spread to other parts of your body. Unlike cancerous tumor(malignant), Benign does not spread to other parts of the body and is safe somehow. Deep neural network techniques can be used to improve the accuracy of early diagnosis significantly.
  Deep Learning is a subfield of machine learning concerned with algorithms inspired by the structure and function of the brain called an artificial neural network.
  A Convolutional Neural Network (ConvNet/CNN) is a.
  What is Dropout.
  What is Batch Normalization
  - It is a technique which is designed to automatically standardize the inputs to a layer in a deep learning neural network.
  e.g. We have four features having different unit after applying batch normalization it comes in similar unit.
  - By Normalizing the output of neurons the activation function will only receive inputs close to zero.
  - Batch normalization ensures a non vanishing gradient.
  We are going to use
  tensorflow 2.3 to build the model. You can install tensorflow by running this command.
  !pip install tensorflow-gpu==2.3.0-rc0
  Importing necessary library that will use in model building..3.0
  pandas for loading and manipulating the data.
  NumPy is used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform and matrices.
  pyplot from matplotlib is used to visualize the results.
  Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.
  import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt
  /usr/local/lib/python3.6/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead. import pandas.util.testing as tm
  from sklearn import datasets, metrics from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler
  Load and return the
  breast cancer classification dataset. The breast cancer dataset is a classic and very easy binary classification dataset.
  cancer = datasets.load_breast_cancer()
  We can view any particular column with the help of
  cancer.DESCR. largest values) of these features were computed for each image, resulting in 30 features. For instance, field 3 is Mean Radius, field 13 is Radius SE, field 23
  We will be using pandas DataFrame to present all our data. We will create a dataframe with our cancer data and target data. It would help us to store all the inputs and outputs in one dataframe.
  X = pd.DataFrame(data = cancer.data, columns=cancer.feature_names) X.head()
  y = cancer.target
  y...])
  cancer.target_names
  array(['malignant', 'benign'], dtype='<U9')
  X.shape
  (569, 30)
  It is not possible for us to manually split our dataset also we need to split the dataset in a random manner. To help us with this task, we will be using a SciKit library named
  train_test_split. We will be using 80% of our dataset for training purposes and 20% for testing.
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0, stratify = y)
  X_train.shape
  (455, 30)
  X_test.shape
  (114, 30)
  StandardScaler removes the mean and scales the data to unit variance.
  scaler = StandardScaler() X_train = scaler.fit_transform(X_train) X_test = scaler.transform(X_test)
  X_train = X_train.reshape(455,30,1) X_test = X_test.reshape(114, 30, 1)
  Now, Let’s go ahead and build our CNN model
  A
  Sequential() function is the easiest way to build a model in Keras. It allows you to build a model layer by layer. Each layer has weights that correspond to the layer the follows it. We use the
  add() function to add layers to our model..
  The
  Rectified Linear Unit(ReLu) is the most commonly used activation function in deep learning models. The function returns 0 if it receives any negative input, but for any positive value x it returns that value back. So it can be written as f(x)=max(0,x)
  To stop problem of shrinkage of data we use concept called
  Padding.
  It has two types:
  - valid
  - same
  Flattening is converting the data into a 1-dimensional array for inputting it to the next layer. We
  flatten the output of the convolutional layers to create a single long feature vector.
  The
  Sigmoid function takes a value as input and outputs another value between 0 and 1. It is non-linear and easy to work with when constructing a neural network model. The good part about this function is that continuously differentiable over different values of z and has a fixed output range.
  epochs = 50 model = Sequential() model.add(Conv1D(filters=32, kernel_size=2, activation='relu', input_shape = (30,1))) model.add(BatchNormalization()) model.add(Dropout(0.2)) model.add(Conv1D(filters=64, kernel_size _________________________________________________________________
  Compile defines the loss function, the optimizer, and the metrics. That’s all. It has nothing to do with the weights and you can compile a model as many times as you want without causing any problem to pretrained weights.
  model.compile(optimizer=Adam(lr=0.00005), loss = 'binary_crossentropy', metrics=['accuracy'])
  Trains the model for a fixed number of epochs (iterations on a dataset).
  history = model.fit(X_train, y_train, epochs=epochs, validation_data=(X_test, y_test), verbose=1)
  ... Epoch 46/50 15/15 [==============================] - 0s 6ms/step - loss: 0.1054 - accuracy: 0.9560 - val_loss: 0.1064 - val_accuracy: 0.9649 Epoch 47/50 15/15 [==============================] - 0s 6ms/step - loss: 0.1373 - accuracy: 0.9473 - val_loss: 0.1074 - val_accuracy: 0.9649 Epoch 48/50 15/15 [==============================] - 0s 7ms/step - loss: 0.1078 - accuracy: 0.9538 - val_loss: 0.1068 - val_accuracy: 0.9649 Epoch 49/50 15/15 [==============================] - 0s 6ms/step - loss: 0.0896 - accuracy: 0.9648 - val_loss: 0.1060 - val_accuracy: 0.9649 Epoch 50/50 15/15 [==============================] - 0s 6ms/step - loss: 0.0927 - accuracy: 0.9648 - val_loss: 0.1047 - val_accuracy: 0.9649()
  A
  history object that contains all information collected during training.
  history.history
  {'accuracy': [0.6197802424430847, 0.7494505643844604, 0.795604407787323, 0.8461538553237915, 0.8395604491233826, 0.8593406677246094, 0.8901098966598511, 0.8791208863258362, 0.8813186883926392, 0.9098901152610779, 0.903296709060669, 0.9230769276618958, ...]}
  plot_learningCurve(history, epochs)
  In
  Model accuracy graph A validation accuracy is always greater than train accuracy thats means our model is not overfitting.
  In
  Model accuracy graph A validation loss is also very lower than training loss so unless and until validation loss goes above than the training loss than we can keep training our model.
  We have successfully created our program to detect breast cancer using
  Deep neural network. We are able to classify cancer effectively with our CNN technique.