Isabel Gwara commited on
Commit
376152d
·
1 Parent(s): 42b052d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -28,8 +28,6 @@ st.subheader('Feeling like you might need a better coping strategy? Take the qui
28
  ### data transformation ###
29
  ### ------------------------------ ###
30
 
31
- global x_train, x_test, y_train, y_test
32
-
33
  # load dataset
34
  uncleaned_data = pd.read_csv('data.csv')
35
 
@@ -98,6 +96,8 @@ def train_model():
98
  # save the model to file
99
  with open('model.pkl', 'wb') as f:
100
  pkl.dump(model, f)
 
 
101
 
102
  ### -------------------------------- ###
103
  ### rerun logic ###
@@ -107,7 +107,7 @@ try:
107
  with open('model.pkl', 'rb') as f:
108
  model = pkl.load(f)
109
  except FileNotFoundError as e:
110
- train_model()
111
 
112
 
113
 
@@ -165,7 +165,7 @@ if form.form_submit_button("Submit to get your recommendation!"):
165
 
166
  col1, col2 = st.columns(2)
167
  col1.metric("Number of Options", len(cat_value_dicts[final_colname]))
168
- col2.metric("Model Accuracy", str(round(metrics.accuracy_score(y_test, y_pred) * 100, 1)) + '%')
169
  st.metric("Most Important Question", get_feat())
170
 
171
 
 
28
  ### data transformation ###
29
  ### ------------------------------ ###
30
 
 
 
31
  # load dataset
32
  uncleaned_data = pd.read_csv('data.csv')
33
 
 
96
  # save the model to file
97
  with open('model.pkl', 'wb') as f:
98
  pkl.dump(model, f)
99
+
100
+ return metrics.accuracy_score(y_test, y_pred)
101
 
102
  ### -------------------------------- ###
103
  ### rerun logic ###
 
107
  with open('model.pkl', 'rb') as f:
108
  model = pkl.load(f)
109
  except FileNotFoundError as e:
110
+ acc = train_model()
111
 
112
 
113
 
 
165
 
166
  col1, col2 = st.columns(2)
167
  col1.metric("Number of Options", len(cat_value_dicts[final_colname]))
168
+ col2.metric("Model Accuracy", str(round(acc * 100, 1)) + '%')
169
  st.metric("Most Important Question", get_feat())
170
 
171