dilkushsingh commited on
Commit
1194aaa
1 Parent(s): 7ccf424

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +41 -0
  2. iris_classifier_model.pkl +3 -0
  3. model.py +30 -0
  4. requirements.txt +5 -0
  5. scaler.pkl +3 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pickle
4
+ from sklearn.preprocessing import StandardScaler
5
+
6
+ # Load the trained model
7
+ with open('iris_classifier_model.pkl', 'rb') as f:
8
+ model = pickle.load(f)
9
+
10
+ # Load the scaler
11
+ with open('scaler.pkl', 'rb') as f:
12
+ scaler = pickle.load(f)
13
+
14
+ # Define the class names
15
+ class_names = ['Setosa', 'Versicolor', 'Virginica']
16
+
17
+ def predict_species(features):
18
+ # Standardize the features
19
+ features = np.array(features).reshape(1, -1)
20
+ features = scaler.transform(features)
21
+
22
+ # Make prediction
23
+ prediction = model.predict(features)
24
+ predicted_species = class_names[prediction[0]]
25
+ return predicted_species
26
+
27
+ # Streamlit app
28
+ st.title("Iris Species Classifier")
29
+ st.write("Enter the features of the Iris flower to classify its species:")
30
+
31
+ # Input fields for the features
32
+ sepal_length = st.number_input('Sepal Length (cm)', min_value=0.0, max_value=10.0, value=5.0)
33
+ sepal_width = st.number_input('Sepal Width (cm)', min_value=0.0, max_value=10.0, value=3.0)
34
+ petal_length = st.number_input('Petal Length (cm)', min_value=0.0, max_value=10.0, value=4.0)
35
+ petal_width = st.number_input('Petal Width (cm)', min_value=0.0, max_value=10.0, value=1.0)
36
+
37
+ # Button to make the prediction
38
+ if st.button('Predict'):
39
+ features = [sepal_length, sepal_width, petal_length, petal_width]
40
+ species = predict_species(features)
41
+ st.write(f'The predicted species is: **{species}**')
iris_classifier_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea02d9bda0503a7a6e3ce99394dec80dc7e84bf35a94eacfe679b54c89b1b7b6
3
+ size 177217
model.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pickle
3
+ from sklearn.datasets import load_iris
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.preprocessing import StandardScaler
6
+ from sklearn.ensemble import RandomForestClassifier
7
+
8
+ # Load the dataset
9
+ iris = load_iris()
10
+ X, y = iris.data, iris.target
11
+
12
+ # Split the data into training and test sets
13
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
14
+
15
+ # Standardize the data
16
+ scaler = StandardScaler()
17
+ X_train = scaler.fit_transform(X_train)
18
+ X_test = scaler.transform(X_test)
19
+
20
+ # Save the scaler
21
+ with open('scaler.pkl', 'wb') as f:
22
+ pickle.dump(scaler, f)
23
+
24
+ # Train the RandomForestClassifier
25
+ model = RandomForestClassifier(n_estimators=100, random_state=42)
26
+ model.fit(X_train, y_train)
27
+
28
+ # Save the model
29
+ with open('iris_classifier_model.pkl', 'wb') as f:
30
+ pickle.dump(model, f)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy==1.24.3
2
+ scikit-learn==1.2.2
3
+ pandas==1.5.3
4
+ streamlit==1.15.1
5
+ distutils
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c8b83a49565446fb922c1f6ca54743848eb0184bd7d4f9a974137fdf2de2769e
3
+ size 545