Atharva Thakur commited on
Commit
6b5f571
1 Parent(s): f9aefdf

Added error handling for MLtoolit in app.py

Browse files
Files changed (2) hide show
  1. app.py +35 -26
  2. requirements.txt +2 -2
app.py CHANGED
@@ -76,36 +76,45 @@ def main():
76
  data_QA.ask_csv()
77
 
78
  if selected == "MLtoolkit":
79
- ml_toolkit = MLToolkit(data)
80
- algorithm, algorithm_type = ml_toolkit.select_algorithm()
81
- X, Y = ml_toolkit.select_features_and_target()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
- if (algorithm_type == "Regressor") and (algorithm == 'Decision Tree' or algorithm == 'Random Forest' or algorithm_type == "Linear Regression"):
84
- params = ml_toolkit.add_parameter_regressor()
85
- else:
86
- params = ml_toolkit.add_parameter_classifier_general()
87
-
88
- if algorithm_type == "Regressor":
89
- algo_model = ml_toolkit.model_regressor(params)
90
- else:
91
- algo_model = ml_toolkit.model_classifier(params)
92
-
93
- x_train, x_test, y_train, y_test = train_test_split(X, Y, train_size=0.8)
94
-
95
- algo_model.fit(x_train, y_train)
96
-
97
- predict = algo_model.predict(x_test)
98
-
99
- if algorithm != 'Linear Regression' and algorithm_type != 'Regressor':
100
- st.write("Training Accuracy is:", algo_model.score(x_train, y_train) * 100)
101
- st.write("Testing Accuracy is:", accuracy_score(y_test, predict) * 100)
102
- else:
103
- st.write("Mean Squared error is:", mean_squared_error(y_test, predict))
104
- st.write("Mean Absolute error is:", mean_absolute_error(y_test, predict))
105
 
106
  # --- DATA PARTY ---
107
  if selected == "Data Party":
108
- st.write("To be continued... :)")
109
 
110
  except:
111
  st.write("Please upload a csv file")
 
76
  data_QA.ask_csv()
77
 
78
  if selected == "MLtoolkit":
79
+ try:
80
+ ml_toolkit = MLToolkit(data)
81
+ algorithm, algorithm_type = ml_toolkit.select_algorithm()
82
+ X, Y = ml_toolkit.select_features_and_target()
83
+
84
+ if (algorithm_type == "Regressor") and (algorithm == 'Decision Tree' or algorithm == 'Random Forest' or algorithm_type == "Linear Regression"):
85
+ params = ml_toolkit.add_parameter_regressor()
86
+ else:
87
+ params = ml_toolkit.add_parameter_classifier_general()
88
+
89
+ if algorithm_type == "Regressor":
90
+ algo_model = ml_toolkit.model_regressor(params)
91
+ else:
92
+ algo_model = ml_toolkit.model_classifier(params)
93
+
94
+ x_train, x_test, y_train, y_test = train_test_split(X, Y, train_size=0.8)
95
+
96
+ algo_model.fit(x_train, y_train)
97
+
98
+ predict = algo_model.predict(x_test)
99
+
100
+ if algorithm != 'Linear Regression' and algorithm_type != 'Regressor':
101
+ st.write("Training Accuracy is:", algo_model.score(x_train, y_train) * 100)
102
+ st.write("Testing Accuracy is:", accuracy_score(y_test, predict) * 100)
103
+ else:
104
+ st.write("Mean Squared error is:", mean_squared_error(y_test, predict))
105
+ st.write("Mean Absolute error is:", mean_absolute_error(y_test, predict))
106
+
107
+ except ValueError as e:
108
+ st.write("ValueError occurred:\n Algorithm Type not suitable for dataset.")
109
+ except TypeError as e:
110
+ st.write("TypeError occurred:\n Please select features and target.")
111
+ except Exception as e:
112
+ st.write("An error occurred:", e)
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  # --- DATA PARTY ---
116
  if selected == "Data Party":
117
+ st.write("To be Added)")
118
 
119
  except:
120
  st.write("Please upload a csv file")
requirements.txt CHANGED
@@ -9,5 +9,5 @@ python-dotenv
9
  tabulate
10
  litellm
11
  streamlit_option_menu
12
- pytest
13
-
 
9
  tabulate
10
  litellm
11
  streamlit_option_menu
12
+ scikit-learn
13
+ pytest