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.
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
- 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
- Downloads brain tumor MRI dataset from Kaggle using
kagglehub - Analyzes class distribution
- Visualizes sample images for each tumor type
- Normalizes pixel values (0-1 range)
- Applies data augmentation techniques:
- Random rotations
- Shifts and zooms
- Horizontal flips
- Calculates class weights to address class imbalance
- 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
- Generates confusion matrix
- Produces detailed classification report
- Calculates AUC-ROC scores
- Visualizes model architecture
- Extracts CNN features as input for classical models
- Trains and evaluates:
- Support Vector Machine (SVM)
- Random Forest
- XGBoost
- Compares performance across all models
- Python 3.8 or higher
- pip or conda package manager
# 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.txttensorflow>=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-
Start Jupyter Notebook:
jupyter notebook
-
Open the main notebook and execute cells sequentially:
- Data loading and exploration
- Preprocessing and augmentation
- Model training
- Evaluation and comparison
- Trained CNN model
- Confusion matrices for all models
- Classification reports (precision, recall, F1-score)
- Performance comparison visualizations
| Model | AUC-ROC |
|---|---|
| CNN | 98% |
| SVM | 39% |
| Random Forest | 52% |
| XGBoost | 51% |
- 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
# Automatic dataset download and exploration
# Visualize class distribution and sample images- CNN trains with real-time validation
- Callbacks monitor performance and optimize hyperparameters
- Comprehensive metrics for model assessment
- Visual comparisons between approaches
- Identify best-performing model
- Analyze misclassifications
- Extract actionable insights
| Component | Technology |
|---|---|
| Deep Learning | TensorFlow/Keras |
| ML Algorithms | scikit-learn, XGBoost |
| Data Processing | NumPy, Pandas |
| Visualization | Matplotlib, Seaborn |
| Dataset API | kagglehub |
| Image Processing | OpenCV |
- Dataset: Kaggle Brain Tumor MRI Dataset
- TensorFlow Documentation: https://www.tensorflow.org
- scikit-learn Guide: https://scikit-learn.org
- CNN Architecture Best Practices: Deep Learning for Medical Image Analysis
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Author: DS-Amarachi
- Repository: DS-Amarachi/Brain_Tumor_Classification
For questions or issues, please open a GitHub Issue.
- 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!