Skip to content

DS-Amarachi/Brain_Tumor_Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Brain Tumor Classification

Python 3.8+ TensorFlow License: MIT

πŸ“‹ Overview

This project implements a deep learning-based approach to classify brain tumors from MRI images. It combines the power of Convolutional Neural Networks (CNNs) with traditional machine learning models to achieve robust and interpretable tumor classification.

The project demonstrates the complete machine learning pipeline: from data loading and preprocessing to model evaluation and comparison, making it an excellent resource for understanding medical image classification.

🎯 Problem Statement

Brain tumors are a serious health concern requiring accurate diagnosis. Manual classification of MRI images is time-consuming and prone to human error. This project leverages artificial intelligence to:

  • Automate brain tumor detection from MRI scans
  • Classify tumor types with high accuracy
  • Compare deep learning vs. traditional ML approaches for medical imaging

πŸ“Š Dataset

  • Source: Kaggle Brain Tumor MRI Classification Dataset
  • Data Loading: Automated download via kagglehub
  • Tumor Types:
    • Glioma
    • Meningioma
    • Pituitary
    • No Tumor
  • Preprocessing: Normalization and class-weight balancing to handle imbalance

πŸ—οΈ Project Architecture

1. Data Loading & Exploration

  • Downloads brain tumor MRI dataset from Kaggle using kagglehub
  • Analyzes class distribution
  • Visualizes sample images for each tumor type

2. Data Preprocessing & Augmentation

  • Normalizes pixel values (0-1 range)
  • Applies data augmentation techniques:
    • Random rotations
    • Shifts and zooms
    • Horizontal flips
  • Calculates class weights to address class imbalance

3. CNN Model Building & Training

  • Constructs a deep Convolutional Neural Network using Keras
  • Implements callbacks:
    • Early Stopping: Prevents overfitting
    • Learning Rate Reduction: Optimizes convergence
  • Trains on augmented data with validation tracking

4. CNN Model Evaluation

  • Generates confusion matrix
  • Produces detailed classification report
  • Calculates AUC-ROC scores
  • Visualizes model architecture

5. Comparison with Traditional ML Models

  • Extracts CNN features as input for classical models
  • Trains and evaluates:
    • Support Vector Machine (SVM)
    • Random Forest
    • XGBoost
  • Compares performance across all models

πŸš€ Installation

Prerequisites

  • Python 3.8 or higher
  • pip or conda package manager

Setup Steps

# Clone the repository
git clone https://github.com/DS-Amarachi/Brain_Tumor_Classification.git
cd Brain_Tumor_Classification

# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install required dependencies
pip install -r requirements.txt

πŸ“¦ Dependencies

tensorflow>=2.0
keras>=2.4
scikit-learn>=0.24
numpy>=1.19
pandas>=1.1
matplotlib>=3.3
seaborn>=0.11
kagglehub>=0.1
opencv-python>=4.5
xgboost>=1.5

Or install via:

pip install -r requirements.txt

πŸŽ“ Usage

Running the Notebook

  1. Start Jupyter Notebook:

    jupyter notebook
  2. Open the main notebook and execute cells sequentially:

    • Data loading and exploration
    • Preprocessing and augmentation
    • Model training
    • Evaluation and comparison

Key Outputs

  • Trained CNN model
  • Confusion matrices for all models
  • Classification reports (precision, recall, F1-score)
  • Performance comparison visualizations

πŸ“ˆ Results

Model Performance Comparison

Model AUC-ROC
CNN 98%
SVM 39%
Random Forest 52%
XGBoost 51%

Key Findings

  • Deep learning (CNN) demonstrates superior performance on medical imaging tasks
  • Feature extraction from CNN provides strong representations for classical ML models
  • Class balancing through weighted loss improves minority class detection
  • Early stopping prevents overfitting while maintaining generalization

πŸ” Detailed Workflow

Step 1: Data Preparation

# Automatic dataset download and exploration
# Visualize class distribution and sample images

Step 2: Model Training

  • CNN trains with real-time validation
  • Callbacks monitor performance and optimize hyperparameters

Step 3: Evaluation

  • Comprehensive metrics for model assessment
  • Visual comparisons between approaches

Step 4: Insights

  • Identify best-performing model
  • Analyze misclassifications
  • Extract actionable insights

πŸ“š Technical Stack

Component Technology
Deep Learning TensorFlow/Keras
ML Algorithms scikit-learn, XGBoost
Data Processing NumPy, Pandas
Visualization Matplotlib, Seaborn
Dataset API kagglehub
Image Processing OpenCV

πŸ”— References


πŸ’‘ Future Enhancements

  • Deploy model as web API (Flask/FastAPI)
  • Implement grad-CAM for model interpretability
  • Add 3D CNN support for volumetric MRI data
  • Create cross-validation pipeline
  • Build web dashboard for predictions
  • Add real-time inference on new MRI scans

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Contributing

Contributions are welcome! Please feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

βœ‰οΈ Contact & Support

For questions or issues, please open a GitHub Issue.


πŸ“Œ Acknowledgments

  • Kaggle community for the brain tumor MRI dataset
  • TensorFlow and scikit-learn open-source communities
  • Medical imaging research community for best practices

⭐ If you find this project helpful, please consider giving it a star!