A production-ready web application and REST API that serves a trained Iris flower classifier. The model (SVM) achieves 96.7% accuracy on the classic Iris dataset.
- Interactive Web UI β Enter sepal/petal measurements and get instant predictions with confidence scores.
- REST API β JSON endpoints for single and batch predictions, model metadata, and health checks.
- High Accuracy β SVM model with 96.7% accuracy, trained on the Iris dataset.
- Model Artifacts β Pre-trained model, scaler, and label encoder included; easily retrain using the provided Jupyter notebook.
- Docker Support β Containerize the app for consistent deployment using Python 3.13.
- Production Ready β Uses Gunicorn as WSGI server; ready for deployment on platforms like Heroku, Render, or AWS.
.
βββ app.py # Flask application with routes and prediction logic
βββ dockerfile # Docker configuration (uses Python 3.13-slim)
βββ Iris.png # Web UI screenshot
βββ requirements.txt # Python dependencies
βββ iris-flower-classification.ipynb # Jupyter notebook for model training
βββ Procfile # For Heroku deployment (Gunicorn)
βββ README.md # This file
βββ templates/
β βββ index.html # Web UI template
βββ (Generated Model Files)
βββ iris_classification_model_20251228_161424.pkl
βββ scaler_20251228_161424.pkl
βββ label_encoder_20251228_161424.pkl
βββ results_summary_20251228_161424.json
| Property | Value |
|---|---|
| Best Model | SVM (Support Vector Machine) |
| Accuracy | 96.67% |
| Features | sepal length (cm), sepal width (cm), petal length (cm), petal width (cm) |
| Classes | setosa, versicolor, virginica |
| Training Date | 2025-12-28 |
The model was trained on the well-known Iris dataset using scikit-learn. The training notebook (iris-flower-classification.ipynb) includes data preprocessing, model comparison, and artifact generation.
- Python 3.13 β the dependencies are specifically tested for this version.
- pip (latest version recommended)
- Docker (optional, for containerized deployment)
-
Clone the repository
git clone https://github.com/MohammadAli-14/Iris-Flower-Classification.git cd Iris-Flower-Classification -
Create and activate a virtual environment
python -m venv .venv source .venv/bin/activate # Linux/Mac .\.venv\Scripts\Activate.ps1 # Windows PowerShell
-
Upgrade pip and install dependencies
python -m pip install --upgrade pip setuptools wheel pip install -r requirements.txt
-
Run the application
python app.py
The app will be available at
http://localhost:5000.
The provided dockerfile uses python:3.13-slim for full compatibility with the project requirements.
-
Build the Docker image
docker build -t iris-classifier . -
Run the container
docker run -p 5000:5000 iris-classifier
Visit http://localhost:5000 in your browser. Use the form to input the four feature values. You can also load sample values for each Iris species using the provided buttons. After clicking Predict Species, the result and class probabilities are displayed.
All endpoints return JSON responses.
Health check to verify that the model is loaded and ready.
curl http://localhost:5000/api/healthReturns metadata about the model (features, classes, model type).
curl http://localhost:5000/api/infoPredict a single sample. Accepts form data (from web UI) or JSON.
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{"features": [5.1, 3.5, 1.4, 0.2]}'Predict multiple samples at once. Expects a JSON object with a samples key containing an array of feature arrays.
curl -X POST http://localhost:5000/batch_predict \
-H "Content-Type: application/json" \
-d '{"samples": [[5.1, 3.5, 1.4, 0.2], [6.0, 2.9, 4.5, 1.5]]}'Single Prediction (Success)
{
"success": true,
"prediction": {
"class": "setosa",
"class_encoded": 0,
"confidence": 0.98,
"probabilities": {
"setosa": 0.98,
"versicolor": 0.02,
"virginica": 0.0
}
},
"input_features": {
"sepal length (cm)": 5.1,
"sepal width (cm)": 3.5,
"petal length (cm)": 1.4,
"petal width (cm)": 0.2
}
}If you wish to retrain the model or experiment with different algorithms, use the Jupyter notebook:
jupyter notebook iris-flower-classification.ipynbThe notebook:
- Loads the Iris dataset from scikit-learn.
- Splits data into training and test sets.
- Scales features using
StandardScaler. - Trains and evaluates multiple classifiers.
- Selects the best model based on accuracy.
- Saves the model, scaler, label encoder, and a results summary.
Note: If you regenerate artifacts, ensure you update the filenames in app.py to match the new timestamps.
For production, the app uses Gunicorn as defined in the Procfile:
web: gunicorn app:app
You can also run it manually:
gunicorn --bind 0.0.0.0:5000 app:app- Ensure the
Procfileis present. - Set the environment to Python 3.13 on the platform.
- Push the code; the platform will automatically install dependencies and start the web process.
- Backend: Flask, Gunicorn
- Machine Learning: scikit-learn, joblib, numpy, pandas
- Frontend: HTML, CSS, JavaScript (vanilla)
- Containerization: Docker
- Development: Jupyter Notebook, Python 3.13
This project is licensed under the MIT License β see the LICENSE file for details.
- The Iris dataset β originally introduced by Ronald Fisher in 1936.
- scikit-learn community for providing excellent machine learning tools.
- Flask for making web development in Python simple and elegant.
β If you find this project useful, please consider giving it a star on GitHub!
