Introduction
Machine Learning is a branch of Artificial Intelligence (AI) that enables systems
to learn from data and make predictions without being explicitly programmed.
In Supervised Machine Learning, models are trained using a labeled dataset,
where:
⚫ input features are provided (such as numerical measurements)
⚫ the correct output labels (classes) are known
⚫ the model learns the relationship between inputs and outputs during
training
After training, the model can predict the class of new, unseen data.
This program implements a supervised classification system using the Iris
dataset, which contains flower measurements and their corresponding species
labels. The goal is to compare multiple machine learning models and select the
one that performs best.
The system follows these main steps:
1. Data Loading – Load the Iris dataset using scikit-learn
2. Data Preparation – Separate features and target labels
3. Train-Test Split – Divide the dataset into training and testing sets
4. Model Building – Create multiple classification models using pipelines
5. Model Training – Train each model on the training data
6. Evaluation – Compare models using accuracy, confusion matrix, and
classification report
7. Model Selection – Choose the best-performing model
8. Prediction – Use the selected model to predict the class of new input
data
This code demonstrates how different supervised learning algorithms—Logistic
Regression, Support Vector Machine (SVM), and Random Forest—can be
trained, evaluated, and compared in a structured workflow.
Such supervised classification systems are commonly used in real-world
applications like:
⚫ flower and plant species classification
⚫ medical diagnosis
⚫ spam email detection
⚫ fraud detection and risk analysis
Objective
The objective of this project is to design and implement a Supervised Machine
Learning–based AI prediction system using Python. The system uses a labeled
dataset to train machine learning models and make predictions on unseen
data.
The project aims to perform the complete supervised learning workflow,
including:
• Data Loading – importing the dataset from a built-in source
• Preprocessing – preparing input features for model training
• Model Training – training machine learning algorithms using labeled data
• Prediction – predicting the output class for new input values
The project also helps in understanding the fundamental components of
supervised learning, such as:
• Features (X) – input variables used by the model for prediction
• Labels (y) – the correct output or class associated with each input
To measure model performance, the trained models are evaluated using:
• Accuracy
• Confusion Matrix
• Classification Report (Precision, Recall, and F1-score)
In addition, multiple machine learning algorithms are compared to understand
their performance differences, and the best-performing model is selected based
on evaluation results.
Finally, the system produces clear and readable outputs that display:
• overall model performance
• sample predictions
• the final predicted result for user-provided input
Dataset Description
Dataset Name: Iris Flower Dataset
Source:
The dataset is loaded using the built-in load_iris() function from the
[Link] module.
Dataset Type:
Multi-class classification dataset
Objective of the Dataset:
The objective of the dataset is to predict the species of an iris flower based on
its physical measurements.
Number of Instances:
• 150 flower samples
Number of Features:
• 4 numerical features
Features (Input Variables):
1. Sepal length (cm)
2. Sepal width (cm)
3. Petal length (cm)
4. Petal width (cm)
Target / Label (Output Classes):
The target variable represents the flower species and contains three classes:
• Setosa
• Versicolor
• Virginica
Class Distribution:
• Each class contains 50 samples, making the dataset balanced.
Why This Dataset is Suitable:
• The dataset is clean and contains no missing values
• Data is already labeled, making it ideal for supervised learning
• Balanced classes help in fair model evaluation
• Suitable for comparing multiple classification algorithms
Preprocessing Used in the Code:
• Standard Scaling is applied using StandardScaler()
• Scaling is important for algorithms such as Logistic Regression and SVM
Train–Test Split:
• The dataset is split into training and testing sets using an 80:20 ratio
• Stratified splitting is used to maintain class balance in both sets
• This helps evaluate how well the model generalizes to unseen data
Model Selection
In supervised learning, the choice of algorithm depends on several factors, such
as:
• the size of the dataset,
• the type of features (numerical or categorical),
• whether the task is classification or regression,
• required accuracy and interpretability.
In this system, three common classification models are compared:
1. Logistic Regression
• Fast and simple baseline classifier
• Works well when classes are linearly separable or reasonably distinct
• Requires feature scaling for optimal performance
2. Support Vector Machine (SVM) with RBF Kernel
• Performs strongly on small to medium-sized datasets
• Can handle non-linear decision boundaries using kernel functions
• Benefits significantly from feature scaling
3. Random Forest
• Ensemble of multiple decision trees
• Can capture non-linear patterns in data
• Less sensitive to feature scaling
Selection Procedure in This Assignment:
• All three models are trained on the training dataset
• Each model is evaluated on the test dataset using accuracy
• The model with the highest test accuracy is selected as the best-performing
model
This approach reflects real-world machine learning practice, where multiple
candidate models are tested and compared using evaluation metrics. Choosing
the best model based on performance ensures more reliable predictions on
unseen data.
Result Analysis
After training and evaluating the three models—Logistic Regression, SVM (RBF
Kernel), and Random Forest—the following observations can be made:
1. Model Accuracy on Test Data:
o Each model was evaluated using the test dataset, and the
accuracy score was recorded.
o For the Iris dataset, multiple models often achieve high accuracy
due to its clean and well-separated classes.
o The model with the highest test accuracy was selected as the best-
performing model.
2. Confusion Matrix Analysis:
o The confusion matrix shows the number of correctly and
incorrectly classified samples for each class.
o Diagonal values represent correctly predicted instances, while off-
diagonal values indicate misclassifications.
o The best model correctly classified most or all test samples,
indicating strong performance.
3. Classification Report:
o The classification report provides precision, recall, and F1-score for
each class:
Precision: proportion of predicted samples for a class that
were correct
Recall: proportion of actual samples for a class that were
correctly predicted
F1-score: harmonic mean of precision and recall
o The report confirms consistent performance across all three
classes.
4. Prediction on New Data:
o The system allows making predictions on new, unseen input
samples.
o Example: a new flower with measurements [5.1, 3.5, 1.4, 0.2] was
predicted as Setosa.
o Class probabilities (if available) indicate the model’s confidence for
each class.
5. Observations:
o Logistic Regression and SVM benefit from feature scaling,
improving performance.
o Random Forest, being tree-based, is less sensitive to scaling.
o The Iris dataset’s simplicity and structure allow high accuracy, but
comparing models ensures that the selected model generalizes
well to unseen data.
Conclusion
This project demonstrates the complete workflow of a supervised machine
learning classification system using the Iris dataset. Multiple models—Logistic
Regression, SVM (RBF Kernel), and Random Forest—were trained, evaluated,
and compared to select the best-performing model.
Key takeaways from this implementation:
The end-to-end process of data loading, preprocessing, training,
evaluation, and prediction was successfully implemented.
Feature scaling was important for models like Logistic Regression and
SVM to achieve optimal performance.
Model evaluation using accuracy, confusion matrix, and classification
report provided a clear understanding of each model’s performance.
Comparing multiple algorithms allowed selection of the most suitable
model for the dataset, reflecting real-world machine learning practice.
The trained model can make accurate predictions on new, unseen data,
demonstrating the system’s practical applicability.
Overall, this assignment illustrates how supervised machine learning models
learn from labeled data, how their performance can be evaluated
systematically, and how model selection ensures reliable predictions.