ChinmayBH commited on
Commit
31dce72
·
verified ·
1 Parent(s): 7cf08f6

added ML algorithms

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -3,8 +3,12 @@ import numpy as np
3
  import pandas as pd
4
  from sklearn.model_selection import train_test_split
5
  from sklearn.neighbors import KNeighborsClassifier
 
 
 
 
6
 
7
- def train_iris_model():
8
  df = pd.read_csv("Iris.csv")
9
  df['Species'] = df['Species'].map({'Iris-setosa': 0, 'Iris-virginica': 1, 'Iris-versicolor': 2})
10
  del df["Id"]
@@ -12,7 +16,18 @@ def train_iris_model():
12
  y = df['Species']
13
  X_train, _, y_train, _ = train_test_split(X, y, test_size=0.3, random_state=42)
14
 
15
- model = KNeighborsClassifier()
 
 
 
 
 
 
 
 
 
 
 
16
  model.fit(X_train, y_train)
17
 
18
  return model
@@ -29,13 +44,20 @@ def predict_iris_species(model, input_data):
29
  def main():
30
  st.title("Iris Species Prediction App")
31
 
 
 
 
 
 
 
 
 
32
  st.sidebar.header("User Input")
33
  sepal_length = st.sidebar.slider("Sepal Length", 0.0, 10.0, 5.0)
34
  sepal_width = st.sidebar.slider("Sepal Width", 0.0, 10.0, 5.0)
35
  petal_length = st.sidebar.slider("Petal Length", 0.0, 10.0, 5.0)
36
  petal_width = st.sidebar.slider("Petal Width", 0.0, 10.0, 5.0)
37
 
38
- trained_model = train_iris_model()
39
  input_values = [sepal_length, sepal_width, petal_length, petal_width]
40
  prediction_result = predict_iris_species(trained_model, input_values)
41
 
@@ -60,4 +82,4 @@ def main():
60
  st.image('versicolor_image.jpg', caption='Iris-versicolor', use_column_width=True)
61
 
62
  if __name__ == "__main__":
63
- main()
 
3
  import pandas as pd
4
  from sklearn.model_selection import train_test_split
5
  from sklearn.neighbors import KNeighborsClassifier
6
+ from sklearn.svm import SVC
7
+ from sklearn.linear_model import LogisticRegression
8
+ from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
9
+ from sklearn.tree import DecisionTreeClassifier
10
 
11
+ def train_iris_model(algorithm):
12
  df = pd.read_csv("Iris.csv")
13
  df['Species'] = df['Species'].map({'Iris-setosa': 0, 'Iris-virginica': 1, 'Iris-versicolor': 2})
14
  del df["Id"]
 
16
  y = df['Species']
17
  X_train, _, y_train, _ = train_test_split(X, y, test_size=0.3, random_state=42)
18
 
19
+ if algorithm == 'KNN':
20
+ model = KNeighborsClassifier()
21
+ elif algorithm == 'SVM':
22
+ model = SVC()
23
+ elif algorithm == "logistic regression":
24
+ model = LogisticRegression()
25
+ elif algorithm == 'Random Forest':
26
+ model = RandomForestClassifier()
27
+ elif algorithm == 'Ada boost classifier':
28
+ model = AdaBoostClassifier()
29
+ elif algorithm == 'Decision tree':
30
+ model = DecisionTreeClassifier()
31
  model.fit(X_train, y_train)
32
 
33
  return model
 
44
  def main():
45
  st.title("Iris Species Prediction App")
46
 
47
+ # Choose ML algorithm for training
48
+ algorithm = st.sidebar.selectbox("Select ML Algorithm", ['KNN', 'SVM', 'logistic regression', 'Random Forest', 'Ada boost classifier', 'Decision tree'])
49
+
50
+ # Train the model based on user's choice
51
+ trained_model = train_iris_model(algorithm)
52
+
53
+ st.image(r"C:\Users\ChinmayB.WINJITBIOS\Downloads\download.jpg")
54
+
55
  st.sidebar.header("User Input")
56
  sepal_length = st.sidebar.slider("Sepal Length", 0.0, 10.0, 5.0)
57
  sepal_width = st.sidebar.slider("Sepal Width", 0.0, 10.0, 5.0)
58
  petal_length = st.sidebar.slider("Petal Length", 0.0, 10.0, 5.0)
59
  petal_width = st.sidebar.slider("Petal Width", 0.0, 10.0, 5.0)
60
 
 
61
  input_values = [sepal_length, sepal_width, petal_length, petal_width]
62
  prediction_result = predict_iris_species(trained_model, input_values)
63
 
 
82
  st.image('versicolor_image.jpg', caption='Iris-versicolor', use_column_width=True)
83
 
84
  if __name__ == "__main__":
85
+ main()