File size: 1,208 Bytes
37d79d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
import numpy as np
import streamlit as st
from sklearn.datasets import load_iris
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

# Load the Iris dataset
iris = load_iris()
X = iris.data
y = iris.target

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create and train the linear regression model
model = LinearRegression()
model.fit(X_train, y_train)

# Streamlit app
st.title("Iris Linear Regression")

# Accept user input
sepal_length = st.number_input("Sepal Length", min_value=0.0, max_value=10.0, value=5.8, step=0.1)
sepal_width = st.number_input("Sepal Width", min_value=0.0, max_value=10.0, value=3.0, step=0.1)
petal_length = st.number_input("Petal Length", min_value=0.0, max_value=10.0, value=3.8, step=0.1)
petal_width = st.number_input("Petal Width", min_value=0.0, max_value=10.0, value=1.2, step=0.1)

# Make prediction
user_input = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
prediction = model.predict(user_input)

# Display the result
st.write(f"The predicted iris species is: {iris.target_names[int(prediction[0])]}")