Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import streamlit as st
|
3 |
+
from sklearn.datasets import load_iris
|
4 |
+
from sklearn.linear_model import LinearRegression
|
5 |
+
from sklearn.model_selection import train_test_split
|
6 |
+
|
7 |
+
# Load the Iris dataset
|
8 |
+
iris = load_iris()
|
9 |
+
X = iris.data
|
10 |
+
y = iris.target
|
11 |
+
|
12 |
+
# Split the data into training and testing sets
|
13 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
14 |
+
|
15 |
+
# Create and train the linear regression model
|
16 |
+
model = LinearRegression()
|
17 |
+
model.fit(X_train, y_train)
|
18 |
+
|
19 |
+
# Streamlit app
|
20 |
+
st.title("Iris Linear Regression")
|
21 |
+
|
22 |
+
# Accept user input
|
23 |
+
sepal_length = st.number_input("Sepal Length", min_value=0.0, max_value=10.0, value=5.8, step=0.1)
|
24 |
+
sepal_width = st.number_input("Sepal Width", min_value=0.0, max_value=10.0, value=3.0, step=0.1)
|
25 |
+
petal_length = st.number_input("Petal Length", min_value=0.0, max_value=10.0, value=3.8, step=0.1)
|
26 |
+
petal_width = st.number_input("Petal Width", min_value=0.0, max_value=10.0, value=1.2, step=0.1)
|
27 |
+
|
28 |
+
# Make prediction
|
29 |
+
user_input = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
30 |
+
prediction = model.predict(user_input)
|
31 |
+
|
32 |
+
# Display the result
|
33 |
+
st.write(f"The predicted iris species is: {iris.target_names[int(prediction[0])]}")
|