An end-to-end Machine Learning pipeline that explores, visualizes, and classifies the classic Iris Dataset. This project trains a machine learning classifier to accurately distinguish between three distinct species of Iris flowers using structural floral features.
This repository contains a structured analytical pipeline divided into three major stages:
Understanding data relationships before modeling via high-quality data visualizations:
- Class Balance Verification: Assessing target variable distributions via frequency count plots.
- Feature Clustering Assessment: Generating a complete pair-wise scatter plot matrix (
pairplot) to see structural boundaries between classes. - Multicollinearity Analysis: Creating a custom correlation heatmap (
coolwarmcolormap) to identify highly correlated independent features.
-
Dimensionality Reduction: Dropping the arbitrary database primary key (
Id) to prevent the model from capturing a synthetic linear pattern. -
Target Label Encoding: Transforming categorical species labels (
Iris-setosa,Iris-versicolor,Iris-virginica) into numerical target integers ($0, 1, 2$ ) usingLabelEncoder. -
Stratified Splitting: Implementing a 20% test split explicitly leveraging
stratify=yto preserve exact target class distributions across training sets and prevent split bias.
- Supervised Learning: Fitting a
DecisionTreeClassifierconfigured with reproducible global random states. - Performance Measurement: Evaluating classification boundaries using overall accuracy, comprehensive classification summaries (precision, recall, f1-score), and visual Confusion Matrices.
- Model Interpretability: Computing exact mathematical feature importance vectors to display which geometric properties dictate flower identification.
| Category | Tools / Libraries Used |
|---|---|
| Core Language | Python 3.x |
| Data Manipulation | pandas, numpy |
| Data Visualization | seaborn, matplotlib |
| Machine Learning | scikit-learn |
The code includes critical data science practices that protect against common model failures:
Why Stratification Matters: The use of
stratify=yensures that each flower class is equally represented in both your training set and testing set. Without this, a random split could accidentally put all of one species into the test set, completely crippling the training process.
The evaluation suite outputs the following diagnostic assets:
- Accuracy Score: Direct percentage metric of overall correct predictions.
- Classification Report: Precision and recall per class to confirm there are no weak spots in individual species identification.
- Feature Importance Chart: Visually ranks features so you can verify if biological assumptions match mathematical model weights (e.g., assessing the predictive power of Petal Width vs. Sepal Length).