iris_detection / app.py
yannthur's picture
Create app.py
23a620c verified
import streamlit as st
import pandas as pd
from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
st.title('simple iris flower prediction app')
st.sidebar.header('user input parameters')
iris = datasets.load_iris()
X = iris.data
y = iris.target
clf = RandomForestClassifier()
clf.fit(X,y)
def user_input_features():
sepal_lenght = st.sidebar.slider('sepal lenght',3.5,8.9,5.4)
# valeur de depart : 3.5
# valeur de fin : 8.9
# valeur de positionement initial : 5.4
sepal_width = st.sidebar.slider('sepal width',2.0,4.4,3.4)
petal_lenght = st.sidebar.slider('petal lenght',1.0,8.9,1.3)
petal_width = st.sidebar.slider('petal width',3.5,8.9,5.4)
data = {'sepal_length':sepal_lenght,
'sepal_width':sepal_width,
'petal_lenght':petal_lenght,
'petal_width':petal_width}
features = pd.DataFrame(data,index = [0])
return(features)
df = user_input_features()
st.subheader('user input features')
st.write(df)
prediction = clf.predict(df)
prediction_proba = clf.predict_proba(df)
st.subheader('class labels and corresponding indexes')
st.write(iris.target_names)
st.subheader('prediction')
st.write(iris.target_names[prediction])
st.subheader('prediction probability')
st.write(prediction_proba)