Spaces:
Sleeping
Sleeping
import streamlit as st # type: ignore | |
import pandas as pd | |
from sklearn import datasets | |
from sklearn.ensemble import RandomForestClassifier | |
st.title('Iris Flower Prediction App') | |
iris = datasets.load_iris() | |
X = iris.data | |
y = iris.target | |
clf = RandomForestClassifier() | |
clf.fit(X,y) | |
st.sidebar.header('User Input Parameters') | |
def user_input_features(): | |
sepal_length = st.sidebar.slider('Sepal length' ,4.3,8.0,5.0) | |
sepal_width = st.sidebar.slider('Sepal width' ,2.0,4.4,3.4) | |
pepal_length = st.sidebar.slider('Petal length' ,1.0,6.9,1.3) | |
petal_width = st.sidebar.slider('Petal width' ,0.1,2.5,0.2) | |
data ={'sepal_length':sepal_length, | |
'sepal_width':sepal_width, | |
'petal_length':pepal_length, | |
'petal_width':petal_width} | |
features = pd.DataFrame(data,index=[0]) | |
return features | |
df = user_input_features() | |
st.subheader('User Input Parameters') | |
st.write(df) | |
prediction = clf.predict(df) | |
prediction_proba = clf.predict_proba(df) | |
st.subheader('Class names and corresponding numbers') | |
st.write(iris.target_names) | |
st.subheader('Prediction') | |
st.write(iris.target_names[prediction]) | |
st.subheader('Prediction Probability') | |
st.write(prediction_proba ) |