Iris Classification and Prediction Web App

 One of my primary interests in the field of computer science is Machine Learning. Machine Learning has no bounds and here, the sky is not the limit. It has applications in many important sectors such as biotechnology, medicine, aviation etc. This is my second web app on Machine Learning and I’m working hard to successfully deploy many more Machine Learning apps. All of these projects are free to use and I welcome any suggestions and/or additions to the project. 

One of the main reasons why I love Machine Learning is that it perfectly incorporates the beauty of mathematics and computer science to successfully integrate and develop a particular application. As I mentioned in the previous article, Machine Learning not only requires a good understanding of coding, it also requires in depth knowledge in Maths. So for the people out there who question the use of Maths in Computer Science, this is a classic example as to why that’s not always the case. Having a good knowledge about calculus and Linear Algebra definitely helps in Data Science. 

After the positive response of our first web app, Diabetes Detector, I decided to explore Machine Learning in greater depth and decided to deploy many more apps related to it in the future. So if you’re interested in Machine Learning and data science, hey we’re on the same page. Although I’m still a junior in high school so most of you might be more experienced than me. 

So coming onto this app, this is an Iris Classification and Prediction App. It classifies and successfully predicts the type of Iris flower based upon a number of user input features such as Sepal Length, Petal Length, Sepal Width and Petal Width. It uses the Random Forest Classifier algorithm. 

The web app uses a simple design and structure. I tried to make it as simple as possible so that it could be deployed easy. The sidebar sliders help in changing the values of the parameters for determination of the result. It also displays class labels, their corresponding index number and the prediction probability along with the predicted species of the Iris Flower. 

Another interesting feature about this web app is the presence of the image of the predicted species. We have 3 different images for all three species which are displayed depending upon the predicted species based upon user input of parameter values. 

We have deployed the app using Streamlit. It is an open source framework that allows data science teams to deploy web apps fairly easily. It’s one of the best hosting services I’ve used and it’s great for quick and easy deployment of web apps. The app is coded in python. 

This web app helped me to improve my experience in Machine Learning and definately helped in my future projects. Feel free to add onto this project and don’t hesitate to drop by any suggestions. Hope you enjoy the app!

Link of the app: https://share.streamlit.io/pranav-coder2005/iris_flower_predictor/main/app.py

About the dataset : The Iris dataset was used in R.A. Fisher’s paper written in 1936, The Use of Multiple Measurements in Taxonomic Problems, and can also be found on the UCI Machine Learning Repository. It is an example of linear discriminant analysis. This dataset is also knows as Anderson’s Iris Dataset because Edgar Anderson collected the data to quantify the morphologic variation of Iris flowers of three related species. 

Based on Fisher’s linear discriminant model, this data set became a typical test case for many statistical classification techniques in machine learning such as support vector machines.

It includes three iris species with 50 samples each as well as some properties about each flower. One flower species is linearly separable from the other two, but the other two are not linearly separable from each other.

Iris is a genus of 260–300 species of flowering plants with showy flowers. Its name is derived from the Greek word for Rainbow (yes, we are quite interested in languages and cultures) which in coincidentally also the name for the Greek goddess of rainbow-Iris. Apart from being the scientific name, Iris is also widely used as a common name for all Iris species.

Dataset License: Open Data Commons Public Domain Dedication and License (PDDL)

Explanation of the Code and how you can make this yourself !

Here, I am going to go through the code in a very concise and simple manner so that people with even minimal experience in programming or data science can follow along and benefit it. This app has been coded in python and has been deployed on streamlit as mentioned before. I’ve also used the Random Forest Classifier Algorithm for this particular problem. 

Alright so lets finally get started. First up I’ve imported the python packages / libraries that I’ve used for this app. More information for them is available on the project template of SkillTools. 

 

import streamlit as st
import pandas as pd
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
from PIL import Image,ImageFilter,ImageEnhance
import os

After this I have included a slight description of the app as a string which includes the dataset resource and the developers. I have given due credits to the original makers of this dataset and have acknowledged the license of the dataset which in this case is Open Data Commons Public Domain Dedication and License (PDDL).

Next we need to give our input features i.e. the parameters of the dataset. The users can manipulate the values of these parameters and run the app. Here we also need to provide the range of these parameters which the users can change using the sliders in the sidebar.

def user_input_features():
    sepal_length = st.sidebar.slider('Sepal length', 4.2, 8.0, 4.4)
    sepal_width = st.sidebar.slider('Sepal width', 1.8, 4.2, 3.2)
    petal_length = st.sidebar.slider('Petal length', 0.8, 7.0, 1.6)
    petal_width = st.sidebar.slider('Petal width', 0.1, 2.4, 0.8)
    data = {'sepal_length': sepal_length,
            'sepal_width': sepal_width,
            'petal_length': petal_length,
            'petal_width': petal_width}
    features = pd.DataFrame(data, index=[0])
    return features

Once we’re done with this, we need to load the Iris dataset and run the Random Forest Classifier Algorithm. Once we give those commands, we finally need to assign class labels, their corresponding index number and the prediction probability of that particular species of iris flower.

iris = datasets.load_iris()
X = iris.data
Y = iris.target

clf = RandomForestClassifier()
clf.fit(X, Y)

prediction = clf.predict(df)
prediction_proba = clf.predict_proba(df)

st.subheader('Class labels and their corresponding index number')
st.write(iris.target_names)

st.subheader('Prediction')
st.write(iris.target_names[prediction])

I’ve also added one more functionality into this web app. It essentially displays an image of the predicted species ! I’ve capped it up with a link of this article and a reference to our Team Skillocity logo.

def load_image(img):
    im =Image.open(os.path.join(img))
    return im

if iris.target_names[prediction] == 'setosa':
    st.text("Showing Setosa Species")
    st.image(load_image('iris_setosa.jpg'))
elif iris.target_names[prediction] == 'versicolor':
    st.text("Showing Versicolor Species")
    st.image(load_image('IRIS_VERSICOLOR.jpg'))
elif iris.target_names[prediction] == 'virginica':
    st.text("Showing Virginica Species")
    st.image(load_image('virginca.jpg'))

So that’s it from this web app and I’ll see you soon with another fun application of Machine Learning / Data Science and give some interesting insights. Hasta pronto !

Iris Classification and Prediction Web App6 min read

4 thoughts on “Iris Classification and Prediction Web App6 min read

  1. whoah this blog is wonderful i really like reading your articles. Keep up the great paintings! You realize, a lot of people are hunting round for this info, you could help them greatly.

Leave a Reply

Your email address will not be published.

Scroll to top