-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSt_app.py
More file actions
31 lines (24 loc) · 1.17 KB
/
St_app.py
File metadata and controls
31 lines (24 loc) · 1.17 KB
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
import streamlit as st
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
@st.cache_data
def load_data():
iris = load_iris()
df = pd.DataFrame(iris.data, columns = iris.feature_names)
df['species'] = iris.target
return df, iris.target_names
df, target_names= load_data()
model = RandomForestClassifier()
model.fit(df.iloc[:,:-1], df["species"])
st.sidebar.title("Input Feature")
sepal_length=st.sidebar.slider("Sepal length", float(df["sepal length (cm)"].min()), float(df["sepal length (cm)"].max()))
sepal_width=st.sidebar.slider("Sepal width", float(df["sepal width (cm)"].min()), float(df["sepal width (cm)"].max()))
petal_length=st.sidebar.slider("Petal length", float(df["petal length (cm)"].min()), float(df["petal length (cm)"].max()))
petal_width=st.sidebar.slider("Petal width", float(df["petal width (cm)"].min()), float(df["petal width (cm)"].max()))
input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
## Prediction
prediction = model.predict(input_data)
predicted_species = target_names[prediction[0]]
st.write("Prediction")
st.write(f"The predicted species is: {predicted_species}")