Skip to content

Commit

Permalink
Iris Flower Classification
Browse files Browse the repository at this point in the history
  • Loading branch information
aviralgarg05 authored Oct 4, 2024
1 parent 0039edc commit 582311a
Show file tree
Hide file tree
Showing 5 changed files with 3,826 additions and 0 deletions.
922 changes: 922 additions & 0 deletions Neural Networks/Iris Flower Classification/SVM Iris.ipynb

Large diffs are not rendered by default.

1,538 changes: 1,538 additions & 0 deletions Neural Networks/Iris Flower Classification/iris.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions Neural Networks/Iris Flower Classification/iris_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
5.4,3.7,1.5,0.2,Iris-setosa
4.8,3.4,1.6,0.2,Iris-setosa
4.8,3,1.4,0.1,Iris-setosa
4.3,3,1.1,0.1,Iris-setosa
5.8,4,1.2,0.2,Iris-setosa
5.7,4.4,1.5,0.4,Iris-setosa
5.4,3.9,1.3,0.4,Iris-setosa
5.1,3.5,1.4,0.3,Iris-setosa
5.7,3.8,1.7,0.3,Iris-setosa
5.1,3.8,1.5,0.3,Iris-setosa
5.4,3.4,1.7,0.2,Iris-setosa
5.1,3.7,1.5,0.4,Iris-setosa
4.6,3.6,1,0.2,Iris-setosa
5.1,3.3,1.7,0.5,Iris-setosa
4.8,3.4,1.9,0.2,Iris-setosa
5,3,1.6,0.2,Iris-setosa
5,3.4,1.6,0.4,Iris-setosa
5.2,3.5,1.5,0.2,Iris-setosa
5.2,3.4,1.4,0.2,Iris-setosa
4.7,3.2,1.6,0.2,Iris-setosa
4.8,3.1,1.6,0.2,Iris-setosa
5.4,3.4,1.5,0.4,Iris-setosa
5.2,4.1,1.5,0.1,Iris-setosa
5.5,4.2,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
5,3.2,1.2,0.2,Iris-setosa
5.5,3.5,1.3,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
4.4,3,1.3,0.2,Iris-setosa
5.1,3.4,1.5,0.2,Iris-setosa
5,3.5,1.3,0.3,Iris-setosa
4.5,2.3,1.3,0.3,Iris-setosa
4.4,3.2,1.3,0.2,Iris-setosa
5,3.5,1.6,0.6,Iris-setosa
5.1,3.8,1.9,0.4,Iris-setosa
4.8,3,1.4,0.3,Iris-setosa
5.1,3.8,1.6,0.2,Iris-setosa
4.6,3.2,1.4,0.2,Iris-setosa
5.3,3.7,1.5,0.2,Iris-setosa
5,3.3,1.4,0.2,Iris-setosa
7,3.2,4.7,1.4,Iris-versicolor
6.4,3.2,4.5,1.5,Iris-versicolor
6.9,3.1,4.9,1.5,Iris-versicolor
5.5,2.3,4,1.3,Iris-versicolor
6.5,2.8,4.6,1.5,Iris-versicolor
5.7,2.8,4.5,1.3,Iris-versicolor
6.3,3.3,4.7,1.6,Iris-versicolor
4.9,2.4,3.3,1,Iris-versicolor
6.6,2.9,4.6,1.3,Iris-versicolor
5.2,2.7,3.9,1.4,Iris-versicolor
5,2,3.5,1,Iris-versicolor
5.9,3,4.2,1.5,Iris-versicolor
6,2.2,4,1,Iris-versicolor
6.1,2.9,4.7,1.4,Iris-versicolor
5.6,2.9,3.6,1.3,Iris-versicolor
6.7,3.1,4.4,1.4,Iris-versicolor
5.6,3,4.5,1.5,Iris-versicolor
5.8,2.7,4.1,1,Iris-versicolor
6.2,2.2,4.5,1.5,Iris-versicolor
5.6,2.5,3.9,1.1,Iris-versicolor
5.9,3.2,4.8,1.8,Iris-versicolor
6.1,2.8,4,1.3,Iris-versicolor
6.3,2.5,4.9,1.5,Iris-versicolor
6.1,2.8,4.7,1.2,Iris-versicolor
6.4,2.9,4.3,1.3,Iris-versicolor
6.6,3,4.4,1.4,Iris-versicolor
6.8,2.8,4.8,1.4,Iris-versicolor
6.7,3,5,1.7,Iris-versicolor
6,2.9,4.5,1.5,Iris-versicolor
5.7,2.6,3.5,1,Iris-versicolor
5.5,2.4,3.8,1.1,Iris-versicolor
5.5,2.4,3.7,1,Iris-versicolor
5.8,2.7,3.9,1.2,Iris-versicolor
6,2.7,5.1,1.6,Iris-versicolor
5.4,3,4.5,1.5,Iris-versicolor
6,3.4,4.5,1.6,Iris-versicolor
6.7,3.1,4.7,1.5,Iris-versicolor
6.3,2.3,4.4,1.3,Iris-versicolor
5.6,3,4.1,1.3,Iris-versicolor
5.5,2.5,4,1.3,Iris-versicolor
5.5,2.6,4.4,1.2,Iris-versicolor
6.1,3,4.6,1.4,Iris-versicolor
5.8,2.6,4,1.2,Iris-versicolor
5,2.3,3.3,1,Iris-versicolor
5.6,2.7,4.2,1.3,Iris-versicolor
5.7,3,4.2,1.2,Iris-versicolor
5.7,2.9,4.2,1.3,Iris-versicolor
6.2,2.9,4.3,1.3,Iris-versicolor
5.1,2.5,3,1.1,Iris-versicolor
5.7,2.8,4.1,1.3,Iris-versicolor
6.3,3.3,6,2.5,Iris-virginica
5.8,2.7,5.1,1.9,Iris-virginica
7.1,3,5.9,2.1,Iris-virginica
6.3,2.9,5.6,1.8,Iris-virginica
6.5,3,5.8,2.2,Iris-virginica
7.6,3,6.6,2.1,Iris-virginica
4.9,2.5,4.5,1.7,Iris-virginica
7.3,2.9,6.3,1.8,Iris-virginica
6.7,2.5,5.8,1.8,Iris-virginica
7.2,3.6,6.1,2.5,Iris-virginica
6.5,3.2,5.1,2,Iris-virginica
6.4,2.7,5.3,1.9,Iris-virginica
6.8,3,5.5,2.1,Iris-virginica
5.7,2.5,5,2,Iris-virginica
5.8,2.8,5.1,2.4,Iris-virginica
6.4,3.2,5.3,2.3,Iris-virginica
6.5,3,5.5,1.8,Iris-virginica
7.7,3.8,6.7,2.2,Iris-virginica
7.7,2.6,6.9,2.3,Iris-virginica
6,2.2,5,1.5,Iris-virginica
6.9,3.2,5.7,2.3,Iris-virginica
5.6,2.8,4.9,2,Iris-virginica
7.7,2.8,6.7,2,Iris-virginica
6.3,2.7,4.9,1.8,Iris-virginica
6.7,3.3,5.7,2.1,Iris-virginica
7.2,3.2,6,1.8,Iris-virginica
6.2,2.8,4.8,1.8,Iris-virginica
6.1,3,4.9,1.8,Iris-virginica
6.4,2.8,5.6,2.1,Iris-virginica
7.2,3,5.8,1.6,Iris-virginica
7.4,2.8,6.1,1.9,Iris-virginica
7.9,3.8,6.4,2,Iris-virginica
6.4,2.8,5.6,2.2,Iris-virginica
6.3,2.8,5.1,1.5,Iris-virginica
6.1,2.6,5.6,1.4,Iris-virginica
7.7,3,6.1,2.3,Iris-virginica
6.3,3.4,5.6,2.4,Iris-virginica
6.4,3.1,5.5,1.8,Iris-virginica
6,3,4.8,1.8,Iris-virginica
6.9,3.1,5.4,2.1,Iris-virginica
6.7,3.1,5.6,2.4,Iris-virginica
6.9,3.1,5.1,2.3,Iris-virginica
5.8,2.7,5.1,1.9,Iris-virginica
6.8,3.2,5.9,2.3,Iris-virginica
6.7,3.3,5.7,2.5,Iris-virginica
6.7,3,5.2,2.3,Iris-virginica
6.3,2.5,5,1.9,Iris-virginica
6.5,3,5.2,2,Iris-virginica
6.2,3.4,5.4,2.3,Iris-virginica
5.9,3,5.1,1.8,Iris-virginica
124 changes: 124 additions & 0 deletions Neural Networks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Iris Flower Classification

## Project Overview

This project aims to classify iris flowers into one of three species:
- **Setosa**
- **Versicolor**
- **Virginica**

Using the measurements of the sepals and petals (length and width), we employ various machine learning models to predict the species of an iris flower. The dataset used for this project is the well-known **Iris dataset**, which is often used for classification tasks in machine learning.

## Objective

The primary goal of this project is to design a machine learning model that can:
- Accurately classify iris flowers based on their sepal and petal measurements.
- Generalize well to new, unseen data to ensure robust predictions in real-world scenarios.

## Dataset Information

- **Classes**: 3 (Setosa, Versicolor, Virginica)
- **Samples per class**: 50
- **Total samples**: 150
- **Features**:
- Sepal length (in cm)
- Sepal width (in cm)
- Petal length (in cm)
- Petal width (in cm)

## Project Workflow

1. **Data Exploration**:
- Visualize the relationships between features using plots like pair plots and correlation matrices.

2. **Data Preprocessing**:
- Standardize the data for better model performance.
- Split the dataset into training and testing sets (e.g., 80% training, 20% testing).

3. **Model Selection**:
- Train multiple classification models to compare performance:
- Decision Tree
- k-Nearest Neighbors (k-NN)
- Support Vector Machine (SVM)
- Logistic Regression
- Naive Bayes

4. **Evaluation**:
- Models are evaluated on the test set using the following metrics:
- Accuracy
- Root Mean Squared Error (RMSE)
- R² Score

5. **Deployment**:
- The best-performing model can be saved and used to predict the species of new iris flowers based on input measurements.

## Getting Started

### Prerequisites

Make sure to install the required libraries before running the project. You can install them using pip:

```bash
pip install numpy pandas scikit-learn matplotlib seaborn
```

### Running the Project

1. **Clone the Repository**:

```bash
git clone https://github.com/yourusername/iris-flower-classification.git
cd iris-flower-classification
```

2. **Run the Script**:

```bash
python iris_classification.py
```

This script will train the model and display performance metrics such as accuracy and RMSE.

## Model Evaluation

The performance of various machine learning models was evaluated on the Iris dataset. The following table summarizes the results of these models, including **accuracy**, **RMSE** (Root Mean Squared Error), and **R² Score**:

| Model | Accuracy | RMSE | R² Score |
|------------------------------|-----------------|--------|----------|
| **Decision Tree Classifier** | 96% | 0.21 | 0.93 |
| **k-Nearest Neighbors (k-NN)**| 95.56% | 0.21 | 0.93 |
| **Support Vector Machine (SVM)**| **98%** | 0.15 | **0.97** |
| **Logistic Regression** (Petals)| 97.78% | 0.15 | 0.97 |
| **Naive Bayes** | 97.78% | 0.15 | 0.97 |

### Key Metrics:
- **Accuracy**: The proportion of correctly classified flowers.
- **RMSE**: A measure of the prediction errors. Lower values indicate better performance.
- **R² Score**: The proportion of variance in the dependent variable that is predictable from the features. Values closer to 1 indicate a better fit.

The **Support Vector Machine (SVM)** achieved the highest accuracy (98%) with the lowest RMSE (0.15) and highest R² score (0.97), making it the best-performing model.

## Visualization

Here are some example visualizations used during data exploration:

1. **Pair Plot**: A visualization to show pairwise relationships between features, colored by species.
2. **Correlation Matrix**: A heatmap to show the correlations between different features.

These visualizations help in understanding how the features are related to each other and how they contribute to the classification of the iris species.

## Conclusion

This project demonstrates the process of building and evaluating machine learning models for classifying iris flowers. Among the models, **SVM** provided the best performance in terms of accuracy and generalization.

## Future Work

- **Hyperparameter Tuning**: Use techniques like Grid Search or Randomized Search to optimize model performance.
- **Advanced Models**: Experiment with more complex algorithms such as **Gradient Boosting** or **Neural Networks**.
- **Deployment**: Convert the model into a web API or mobile app for real-time iris classification.

## References

- [Iris Dataset - UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/iris)
- [Scikit-learn Documentation](https://scikit-learn.org/stable/)

0 comments on commit 582311a

Please sign in to comment.