0% found this document useful (0 votes)
14 views

AttiqAhmadAfsarMLAssignment3Flask

Uploaded by

Attiq Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

AttiqAhmadAfsarMLAssignment3Flask

Uploaded by

Attiq Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment 3

Submitted To:

Dr .Abid Ali

Submitted By:

Attiq Ahmad Afsar

Course Title:

Machine Learning Lab

Deadline:

Dec 7, 2024

Semester:

7th
Report on Flower Species Classification Web Application

Table of Contents
1. Introduction

2. Steps and Implementation

3. Evaluation

4. Conclusion

5. References

1. Introduction
The goal of this project is to develop a web application using Flask that classifies flowers into species
based on images uploaded by users. The system leverages machine learning algorithms, specifically
Random Forest, trained on the Iris dataset, to predict the species of a flower. The web interface allows
users to upload images, which are then processed and classified by the model. This report provides an
overview of the key steps in implementing this system, including data preprocessing, model training, and
user interface design.

2. Steps and Implementation


2.1 Loading and Preprocessing the Iris Dataset
The application uses the Iris dataset, which contains data about three species of Iris flowers. The dataset is
preprocessed to handle missing values and normalize the feature values for consistency.

1. Handling Missing Data: Missing values in the dataset are handled using the
`SimpleImputer` class from `sklearn`, replacing missing values with the mean of the column.
2. Normalization: The feature values are normalized using the `StandardScaler` to ensure that all
features are on the same scale, improving the performance of machine learning algorithms.
3. Train-Test Split: The data is divided into training and testing subsets (70% training, 30% testing)
to evaluate model performance effectively.

2.2 Extracting Features from Uploaded Images


The application allows users to upload images of flowers. Once an image is uploaded, the following steps
are performed:

1. Grayscale Conversion:The image is converted into grayscale using OpenCV’s `cv2.cvtColor`


function.
2. Thresholding: A binary threshold is applied to segment the image and isolate the flower from the
background.
3. Contour Detection: Contours are detected using OpenCV’s `cv2.findContours` method. The
largest contours are used to extract the key features (width and height) of the flower.
4. Feature Extraction: The width and height of the largest contours are extracted as features, which
are then used for classification.

2.3 Model Training with Random Forest


The model used for classification is a Random Forest Classifier. This robust ensemble learning
algorithm was trained using the preprocessed Iris dataset.

1. The model was trained on the normalized training data (features and corresponding species
labels).
2. The model was evaluated on the testing set, where its performance was measured using accuracy,
confusion matrix, and other classification metrics.

2.4 User Interface and File Upload


The user interface is designed using HTML and Flask templates. The interface allows users to upload
flower images through a simple form.

1. Homepage: The homepage (`index.html`) provides a button for users to upload flower images.
2. File Upload: The file is uploaded via the `upload_file` route, where the image is saved to the
server. The image is processed to extract features, and the model predicts the species based on the
extracted features.
3. Result Display: After classification, the predicted species is displayed on the result page
(`result.html`). Users can upload another image for classification.

2.5 Model Evaluation and Performance Metrics


Once the model is trained and tested, it is evaluated using the following metrics:

1. Accuracy: The accuracy of the model is calculated to measure the proportion of correct
predictions out of the total predictions.
2. Confusion Matrix: The confusion matrix is used to visualize the model’s performance, indicating
how well the model distinguishes between different classes.
3. Classification Report: Precision, recall, and F1-score are calculated for each class to provide
deeper insights into the model’s performance.
3. Evaluation
The system performs reasonably well in predicting flower species. The Random Forest model was chosen
for its ability to handle complex classification tasks with high accuracy. The preprocessing steps ensure
that the dataset is clean and normalized, while the feature extraction from images captures the key
characteristics of the flowers.

1. Accuracy: The model achieved a high classification rate on the test set.
2. Confusion Matrix: The confusion matrix revealed that the model performs equally well in
distinguishing all three flower species.
3. User Experience: The user interface is intuitive and responsive, allowing users to upload images
and receive instant predictions.
4. Screen Shots Of project
Test No:2
File and Folder Structure:
5. Conclusion
This project demonstrates the integration of machine learning with a web-based interface to solve a real-
world classification problem. The use of the Iris dataset, along with Random Forest for classification,
provides an effective solution for predicting flower species based on image features. The system is
userfriendly, robust, and provides accurate results, making it a useful tool for flower species
classification.

5.Tools And Libraries


1. Flask
2. Sk-learn
3. Numpy
4. PIL(pillow)
5. Open-CV(CV2)

6. References
1. Scikit-learn Documentation: [https://scikit-learn.org/](https://scikit-learn.org/)
2. OpenCV Documentation: [https://opencv.org/](https://opencv.org/)

You might also like