-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiris2.py
43 lines (36 loc) · 1.41 KB
/
iris2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import library needed
import pandas as pd
import streamlit as st
import pickle
import numpy as np
# Load the model
with open('iris_model.pkl', 'rb') as f:
model = pickle.load(f)
# adding images
species = ['setosa', 'versicolor', 'virginica']
image = ['setosa.jpg', 'versicolor.jpg', 'virginica.jpg']
# title and explanation
st.title("Iris Flower Classification")
st.write("This app correctly classifies iris flower among 3 possible species")
# Creating Sidebar for inputs
st.sidebar.title("Inputs")
sepal_length = st.sidebar.slider("sepal length (cm)", 4.3, 7.9, 5.0)
sepal_width = st.sidebar.slider("sepal width (cm)", 2.0, 4.4, 3.6)
petal_length = st.sidebar.slider("petal length (cm)", 1.0, 6.9, 1.4)
petal_width = st.sidebar.slider("petal width (cm)", 0.1, 2.5, 0.2)
# Button to trigger prediction
if st.button("Predict"):
# Getting Prediction from model
inp = np.array([sepal_length, sepal_width, petal_length, petal_width])
inp = np.expand_dims(inp, axis=0)
prediction = model.predict(inp)
# Show Results when the button is clicked
st.write('''
## Results
Following is the probability of each class
''')
df = pd.DataFrame(prediction, index=['result'], columns=species)
st.dataframe(df)
result = species[np.argmax(prediction)]
st.write("**This flower belongs to " + result + " class**")
st.image(image[np.argmax(prediction)])