Skip to content

🧠 A Flask web app for predicting breast cancer (Malignant or Benign) using scikit-learn with clean data, real-time form input, and deploy-ready on Render.

License

Notifications You must be signed in to change notification settings

Someshog/Breast-cancer-flask-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ Breast Cancer Prediction Web Application

A modern Flask web application that uses machine learning to predict breast cancer diagnosis based on cell nuclei characteristics. Built with Python, Flask, and scikit-learn.

Python Flask Scikit-learn Bootstrap

🌟 Features

  • AI-Powered Predictions: Uses Extra Trees Classifier with 100% F1 score on validation data
  • Modern UI: Responsive design with Bootstrap 5, loading animations, and intuitive interface
  • Real-time Analysis: Instant predictions with confidence scores and risk assessment

πŸš€ Live Demo

https://breast-cancer-flask-app.onrender.com/

πŸ“Š Model Performance

  • Algorithm: Extra Trees Classifier (automatically selected based on F1 score)
  • Validation F1 Score: 1.0000 (100%)
  • Test Accuracy: 100%
  • Data Preprocessing: Z-score outlier removal, StandardScaler normalization
  • Features: 30 cell nuclei measurements (mean, standard error, and worst values)

πŸ› οΈ Technology Stack

  • Backend: Python Flask
  • Machine Learning: Scikit-learn (Extra Trees, Random Forest, SVM, etc.)
  • Frontend: HTML5, CSS3, Bootstrap 5, JavaScript
  • Data Processing: NumPy, Pandas
  • Model Persistence: Joblib

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)

πŸ”§ Installation & Setup

1. Clone the repository

git clone https://github.com/yourusername/breast-cancer-prediction-web.git
cd breast-cancer-prediction-web

2. Create a virtual environment (recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Run the application

python app.py

5. Open your browser

Navigate to http://localhost:5000

πŸ”„ How It Works

  1. Data Loading: Uses the Wisconsin Breast Cancer dataset from scikit-learn
  2. Data Cleaning: Removes outliers using Z-score method (threshold: 3)
  3. Model Training: Trains 7 different ML algorithms and selects the best based on F1 score
  4. Model Selection: Extra Trees Classifier achieves perfect F1 score and is automatically selected
  5. Prediction: User inputs cell measurements β†’ Model predicts Benign/Malignant with confidence

πŸ“ Project Structure

breast-cancer-prediction-web/
β”‚
β”œβ”€β”€ app.py                 # Main Flask application
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ Procfile              # For Heroku deployment
β”œβ”€β”€ runtime.txt           # Python version for deployment
β”œβ”€β”€ README.md             # Project documentation
β”œβ”€β”€ .gitignore           # Git ignore file
β”‚
β”œβ”€β”€ models/              # ML models (auto-generated)
β”‚   β”œβ”€β”€ breast_cancer_model.pkl
β”‚   └── scaler.pkl
β”‚
β”œβ”€β”€ templates/           # HTML templates
β”‚   β”œβ”€β”€ index.html       # Main prediction page
β”‚   └── about.html       # About page
β”‚
└── static/             # Static files
    β”œβ”€β”€ css/
    β”‚   └── style.css    # Custom styles
    └── js/
        └── script.js    # Frontend JavaScript

πŸ”Œ API Endpoints

Main Routes

  • GET / - Main prediction interface
  • POST /predict - Make prediction (JSON response)
  • GET /about - About page
  • GET /api/model-info - Model information and metrics

API Usage Example

curl -X POST http://localhost:5000/predict \
  -d "mean radius=14.6" \
  -d "mean texture=22.7" \
  [... other 28 features]

Response:

{
  "prediction": "Benign",
  "confidence": {
    "benign": "71.0%",
    "malignant": "29.0%"
  },
  "risk_level": "Low Risk",
  "confidence_score": 0.71
}

πŸš€ Deployment Options

Option 1: Heroku (Free Tier)

# Install Heroku CLI, then:
heroku create your-app-name
git push heroku main

Option 2: Render

  1. Connect your GitHub repo to Render
  2. Select "Web Service"
  3. Build command: pip install -r requirements.txt
  4. Start command: python app.py

Option 3: Railway

  1. Connect GitHub repo to Railway
  2. Deploy automatically with zero configuration

Option 4: Local Network

python app.py
# Access via http://your-ip:5000

⚠️ Medical Disclaimer

IMPORTANT: This application is for educational and research purposes only. It should NOT be used for actual medical diagnosis or treatment decisions. Always consult with qualified healthcare professionals for medical advice.

🀝 Contributing

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

πŸ“„ License

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

πŸ™ Acknowledgments

  • Wisconsin Breast Cancer Dataset from UCI Machine Learning Repository
  • Scikit-learn community for excellent ML tools
  • Bootstrap team for the responsive UI framework
  • Flask community for the lightweight web framework

⭐ Star this repository if you found it helpful!

About

🧠 A Flask web app for predicting breast cancer (Malignant or Benign) using scikit-learn with clean data, real-time form input, and deploy-ready on Render.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published