Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn import datasets
|
4 |
+
from sklearn.ensemble import RandomForestClassifier
|
5 |
+
|
6 |
+
st.write("""
|
7 |
+
# Simple Iris Flower Prediction App
|
8 |
+
|
9 |
+
This app predicts the **Iris flower** type!
|
10 |
+
""")
|
11 |
+
|
12 |
+
st.sidebar.header('User Input Parameters')
|
13 |
+
|
14 |
+
def user_input_features():
|
15 |
+
sepal_length = st.sidebar.slider('Sepal length', 4.3, 7.9, 5.4)
|
16 |
+
sepal_width = st.sidebar.slider('Sepal width', 2.0, 4.4, 3.4)
|
17 |
+
petal_length = st.sidebar.slider('Petal length', 1.0, 6.9, 1.3)
|
18 |
+
petal_width = st.sidebar.slider('Petal width', 0.1, 2.5, 0.2)
|
19 |
+
data = {'sepal_length': sepal_length,
|
20 |
+
'sepal_width': sepal_width,
|
21 |
+
'petal_length': petal_length,
|
22 |
+
'petal_width': petal_width}
|
23 |
+
features = pd.DataFrame(data, index=[0])
|
24 |
+
return features
|
25 |
+
|
26 |
+
df = user_input_features()
|
27 |
+
|
28 |
+
st.subheader('User Input parameters')
|
29 |
+
st.write(df)
|
30 |
+
|
31 |
+
iris = datasets.load_iris()
|
32 |
+
X = iris.data
|
33 |
+
Y = iris.target
|
34 |
+
|
35 |
+
clf = RandomForestClassifier()
|
36 |
+
clf.fit(X, Y)
|
37 |
+
|
38 |
+
prediction = clf.predict(df)
|
39 |
+
prediction_proba = clf.predict_proba(df)
|
40 |
+
|
41 |
+
st.subheader('Class labels and their corresponding index number')
|
42 |
+
st.write(iris.target_names)
|
43 |
+
|
44 |
+
st.subheader('Prediction')
|
45 |
+
st.write(iris.target_names[prediction])
|
46 |
+
#st.write(prediction)
|
47 |
+
|
48 |
+
st.subheader('Prediction Probability')
|
49 |
+
st.write(prediction_proba)
|