An end-to-end machine learning pipeline for classifying Iris species. From data preparation and model training to evaluation and a Flask API for live predictions.
- Data Preparation
- Load raw CSV, minimal cleaning, stratified train/test split
- Model Training
- Standard scaling + Logistic Regression
- Evaluation
- Accuracy, classification report, confusion matrix
- API Service
- Flask app exposing
/predictendpoint for JSON input
- Flask app exposing
- Serialization
- Model saved as
models/iris_classifier.joblib
- Model saved as
iris-classifier/ βββ data/ β βββ raw/ # raw iris.csv β βββ processed/ # train.csv & test.csv β βββ images/ β βββ iris_flowers.png # illustration used in README β βββ models/ β βββ iris_classifier.joblib # trained model pipeline β βββ src/ β βββ data_prep.py # data loading & train/test split β βββ train.py # build & train model pipeline β βββ evaluate.py # compute metrics & print reports β βββ app.py # Flask API for live inference β βββ requirements.txt # project dependencies βββ README.md # this file
- Install dependencies
pip install -r requirements.txt
- Prepare the data
python src/data_prep.py
- Train the model
python src/train.py
--input data/processed/train.csv
--output models/iris_classifier.joblib
- Evaluate Performance
python src/evaluate.py
--model-path models/iris_classifier.joblib
--test-data data/processed/test.csv
π₯οΈ Running the Flask API
cd src flask run --host=0.0.0.0 --port=5000
/predict Endpoint
Send a POST request with JSON body: { "sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2 }
Response
{ "predicted_species": "Setosa", "confidence": 0.96 }
