adityaardak commited on
Commit
923450e
·
verified ·
1 Parent(s): 3e720f7

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +34 -0
  2. model.pkl +3 -0
  3. train_model.py +33 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import numpy as np
4
+
5
+ # Load the saved model
6
+ with open('model.pkl', 'rb') as f:
7
+ model = pickle.load(f)
8
+
9
+ st.title("Iris Flower Prediction App")
10
+
11
+ st.write("""
12
+ Enter the **Iris flower measurements** below to predict the species.
13
+ """)
14
+
15
+ # Create input widgets for each feature
16
+ sepal_length = st.number_input("Sepal length (cm)", min_value=0.0, max_value=10.0, value=5.0)
17
+ sepal_width = st.number_input("Sepal width (cm)", min_value=0.0, max_value=10.0, value=3.0)
18
+ petal_length = st.number_input("Petal length (cm)", min_value=0.0, max_value=10.0, value=4.0)
19
+ petal_width = st.number_input("Petal width (cm)", min_value=0.0, max_value=10.0, value=1.0)
20
+
21
+ if st.button("Predict"):
22
+ # 1. Convert input to a numpy array
23
+ input_data = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
24
+
25
+ # 2. Make prediction
26
+ prediction = model.predict(input_data)
27
+
28
+ # 3. Map numeric prediction to Iris class name
29
+ # (Iris dataset classes -> 0: setosa, 1: versicolor, 2: virginica)
30
+ class_names = ["Iris-setosa", "Iris-versicolor", "Iris-virginica"]
31
+ predicted_class = class_names[prediction[0]]
32
+
33
+ # 4. Display the result
34
+ st.write(f"**Predicted Iris Species:** {predicted_class}")
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d969c8137d8d3e7d96545046c1c3ee9b2342bcb18daf82c49b25415e0450ea2
3
+ size 835
train_model.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.datasets import load_iris
3
+ from sklearn.model_selection import train_test_split
4
+ from sklearn.linear_model import LogisticRegression
5
+ import pickle
6
+
7
+ # 1. Load the iris dataset
8
+ iris = load_iris()
9
+ X = iris.data # features
10
+ y = iris.target # labels
11
+
12
+ # 2. Convert to a DataFrame (optional, for illustration)
13
+ df = pd.DataFrame(X, columns=iris.feature_names)
14
+ df['target'] = y
15
+
16
+ # 3. Train-test split
17
+ X_train, X_test, y_train, y_test = train_test_split(X, y,
18
+ test_size=0.2,
19
+ random_state=42)
20
+
21
+ # 4. Train a simple Logistic Regression model
22
+ model = LogisticRegression(max_iter=200)
23
+ model.fit(X_train, y_train)
24
+
25
+ # 5. Evaluate the model (optional, just to see performance)
26
+ accuracy = model.score(X_test, y_test)
27
+ print(f"Model accuracy: {accuracy:.2f}")
28
+
29
+ # 6. Save the trained model as a pickle file
30
+ with open('model.pkl', 'wb') as f:
31
+ pickle.dump(model, f)
32
+
33
+ print("Model has been trained and saved as model.pkl")