Skip to content

saanidhi-git/Irisi-Flower-Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒธ Iris Flower Classification with K-Nearest Neighbors (KNN)

Table of Contents

  1. Project Overview
  2. Algorithm Used (KNN)
  3. Dataset
  4. Project Structure
  5. Setup and Installation
  6. How to Run the Streamlit App
  7. Results and Visualization
  8. Conclusion

1. Project Overview

This project demonstrates a classic Machine Learning classification task: identifying the species of an Iris flower based on its physical measurements. We utilize the K-Nearest Neighbors (KNN) algorithm to build a robust model and package the solution in an interactive web application using Streamlit.

Key Features:

  • Data Analysis: Exploratory Data Analysis (EDA) of the Iris dataset.
  • Model Training: KNN implementation using scikit-learn.
  • Interactive App: A Streamlit interface for real-time classification input.

2. Algorithm Used (KNN)

The core of this project is the K-Nearest Neighbors (KNN) algorithm.

  • How it Works: KNN is a non-parametric, lazy learning algorithm. It classifies a new data point based on the majority class among its $K$ nearest neighbors. The 'distance' (Euclidean distance is typically used) is calculated between the new point and all existing data points to find the closest ones.
  • Hyperparameter: The value of K (the number of neighbors) was chosen to be [Insert your K value, e.g., 5] after initial testing showed optimal performance.

3. Dataset

This project uses the famous Iris flower dataset, which is often called the "Hello World" of Machine Learning.

Feature Description Unit
sepal_length Length of the sepal cm
sepal_width Width of the sepal cm
petal_length Length of the petal cm
petal_width Width of the petal cm
species The target class (Setosa, Versicolor, or Virginica) N/A

4. Project Structure

The repository is organized as follows: iris-classification-knn/ โ”œโ”€โ”€ .gitignore โ”œโ”€โ”€ README.md โ”œโ”€โ”€ requirements.txt # Lists all necessary Python libraries โ”œโ”€โ”€ iris_classifier.py # Main ML code: loads data, trains KNN, saves model. โ””โ”€โ”€ streamlit_app.py # Streamlit code for the interactive web interface.


5. Setup and Installation

To run this project locally, follow these steps:

  1. Clone the repository:

    git clone [https://github.com/YourUsername/iris-classification-knn.git](https://github.com/YourUsername/iris-classification-knn.git)
    cd iris-classification-knn
  2. Create and activate a virtual environment (Recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  3. Install the required libraries:

    pip install -r requirements.txt
  4. Run the ML Training Script: This will train the KNN model and create the necessary artifacts (like a serialized model file).

    python iris_classifier.py

6. How to Run the Streamlit App

The project includes an interactive Streamlit application for demonstration.

  1. Ensure you have completed the Setup steps above.

  2. Run the Streamlit app:

    streamlit run streamlit_app.py
  3. The app will automatically open in your web browser at a local address (usually http://localhost:8501).

๐Ÿ“ท Streamlit Application Preview

Screenshot 2025-10-15 202057
Figure 1: Streamlit App Interface showing sliders for input features and the predicted species.


7. Results and Visualization

Model Performance

The K-Nearest Neighbors (KNN) classifier achieved the following performance metrics on the test set:

  • Accuracy: [Insert your calculated Accuracy Score]%

Data Visualization

A key step in classification is visualizing the data to understand class separability. The pairplot below illustrates how the three species cluster based on the features.

IFC1
Figure 2: Scatter plot of Petal Length vs. Petal Width, clearly separating the three Iris species, confirming the data's separability for the KNN model.


8. Conclusion

The KNN algorithm proved highly effective for classifying the Iris species, achieving high accuracy. The Streamlit app provides a simple, intuitive way to interact with the trained model, making this a complete and accessible Machine Learning project for demonstration and learning.

About

Iris Flower Species Classification ๐ŸŒธ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published