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