Brain Tumor Classification using Machine Learning.

Brain Tumor Classification using Machine Learning.

About Brain Tumor Classification:-

In this machine learning project, we build a classifier to detect the brain tumor from the MRI scan images.

Brain Tumor Classification Dataset

The images are split into two folders yes and no each containing images with and without brain tumors respectively. There are a total of 253 images. This Dataset Download from Kaggle.

Tools and Libraries used

  • Python
  • Tensorflow
  • Keras
  • Numpy
  • Scikit-learn
  • Matplotlib
  • OpenCV

Step to Develop Brain Tumor Classifier:-

  1. Perform Exploratory Data Analysis (EDA) on brain tumor dataset
  2. Build a CNN model
  3. Train and Evaluate our model on the dataset

Step 1. Perform Exploratory Data Analysis (EDA)

The brain tumor dataset contains 2 folders “no” and “yes” with 98 and 155 images each. Load the folders containing the images to our current working directory. Using the imutils module, we extract the paths for all the images and store them in a list called image_paths.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 2: Build a CNN Model

Before going on to build an architecture for our classifier, let’s understand what CNN is.

A Convolutional Neural Network or CNN for short is a deep neural network widely used for analyzing visual images. These types of networks work well for tasks like image classification and detection, and image segmentation. There are 2 main parts of a CNN:

  • A convolutional layer that does the job of feature extraction
  • A fully connected layer at the end that utilizes the output of the convolutional layers and predicts the class of the image.

TensorFlow provides ImageDataGenerator which is used for data augmentation. Data Augmentation is extremely helpful in cases where the input data is very less. So we use different transformations to increase the dataset size. It provides various transformations like rotation, flipping images horizontally, vertically, zoom, etc…

We are using the transformations fill_mode and rotation_range to fill the out-of-boundary pixels with the pixel “nearest” to them and include a rotation of 15 degrees to the images.

Step 3: Train and evaluate the model

Before we start training our model, let’s store the following hyperparameters. The model is trained on 10 epochs (full iterations) with train_steps for the training set and validation_steps for the validation set in each epoch. The batch size for each epoch is taken as 8. Now, let’s train our model.

Our model got 96.15% accuracy on the test set. Now let’s evaluate our model using the predict() function.

The predictions made by the model will be an array with each value being the probability that it predicts the image belongs to that category. So, we take the maximum of all such probabilities and assign the predicted label to that image input.

A confusion matrix is a matrix representation showing how well the trained model predicts each target class with respect to the counts. It contains 4 values in the following format:

TP FN

FP TN

  • True positive (TP): Target is positive and the model predicted it as positive
  • False-negative (FN): Target is positive and the model predicted it as negative
  • False-positive (FP): Target is negative and the model predicted it as positive
  • True negative (TN): Target is negative and the model predicted it as negative

The classification report provides a summary of the metrics precision, recall, and F1 score for each class/label in the dataset. It also provides the accuracy and how many dataset samples of each label it categorized.

Now, let’s find the overall accuracy of the model using the formula: (TP + TN) / (TP + FN + FN + TN)

Summary:- So the conclusion is that we summaries as it has been repeatedly noted, the number of patients with a brain tumor is growing, including due to improved quality of treatment of brain tumor we can save many people who are suffering from so We build a binary classification using transfer learning to detect tumor from MRI scan images. This obtained accuracy up to 96.5% and visualizes our model's overall performance.

To view or add a comment, sign in

Others also viewed

Explore content categories