Lung Cancer Detection using Convolutional Neural Network (CNN)
Last Updated : 10 Apr, 2026
Computer Vision is one of the applications of deep neural networks and one such use case is in predicting the presence of cancerous cells. In this article, we will learn how to build a classifier using Convolution Neural Network which can classify normal lung tissues from cancerous tissues.
The following process will be followed to build this classifier:
After defining the model architecture we will compile the model with an optimizer, loss function and evaluation metric then train it using the training data.
We use the Adam optimizer which adjusts the learning rate during training to speed up convergence.
Categorical cross entropy loss is appropriate as loss function for multi-class classification problems as it measures the difference between the predicted and actual probability distributions.
EarlyStopping:Stops training if validation accuracy doesnβt improve for a set number of epochs (patience).
ReduceLROnPlateau: Reduces learning rate when validation loss plateaus, controlled by patience and factor.
Custom myCallback class: Stops training early when validation accuracy exceeds 90%.
self.model.stop_training = True: Signals to stop training inside the callback.
Let's visualize the training and validation accuracy with each epoch.
pd.DataFrame(history.history) converts training history into a DataFrame.
history_df.loc[:, ['accuracy', 'val_accuracy']].plot() plots training and validation accuracy.
Output:
This graph shows the training and validation accuracy of the model over epochs. The training accuracy increases steadily reaching near 1.0 indicating the model is learning well from the training data. Although it's the case of overfitting