This project trains a machine-learning classifier to predict an Iris flower species from four measurements:
- Sepal length (cm)
- Sepal width (cm)
- Petal length (cm)
- Petal width (cm)
The target column is Species. The Id column is an identifier and is excluded from model training.
The project uses the Iris.csv file supplied for the CodeAlpha internship task. It contains 150 rows and 6 columns. The dataset has three species labels: Iris-setosa, Iris-versicolor, and Iris-virginica.
- Load and inspect the dataset with pandas.
- Check missing values and species distribution.
- Visualize species counts and feature relationships.
- Split data into training (80%) and test (20%) sets using stratification.
- Train a pipeline with
StandardScalerandLogisticRegression. - Evaluate the model using test accuracy, precision, recall, F1-score, and a confusion matrix.
- Demonstrate a prediction for a sample flower.
Make sure Iris.csv, iris_classification.py, and requirements.txt are in the same folder.
python -m venv .venv
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation, you can use Command Prompt instead:
.venv\Scripts\activate.batpython -m pip install --upgrade pip
pip install -r requirements.txtpython iris_classification.pyThe script prints the dataset overview, test accuracy, classification report, and a sample prediction. It also creates an outputs folder containing:
species_distribution.pngfeature_relationships.pngconfusion_matrix.png
- The test score depends on the split and model. Do not claim a score until you run the script and see the actual output.
- This is a small educational dataset, so test accuracy is not a guarantee of performance on every real-world flower sample.