matsammut commited on
Commit
d58f189
·
verified ·
1 Parent(s): 32a9314

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -33,7 +33,7 @@ def predict_ann(age, workclass, education, marital_status, occupation, relations
33
  # prediction = 1
34
  return "Income >50K" if prediction == 1 else "Income <=50K"
35
 
36
- def rf_interface(age, workclass, education, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
37
  # columns = {
38
  # "age": [age], "workclass":[workclass], "educational-num":[education], "marital-status":[marital_status], "occupation":[occupation],
39
  # "relationship":[relationship], "race":[race], "gender":[gender], "capital-gain":[capital_gain], "capital-loss":[capital_loss],
@@ -54,6 +54,28 @@ def rf_interface(age, workclass, education, marital_status, occupation, relation
54
  # prediction = 1
55
  return "Income >50K" if prediction == 1 else "Income <=50K"
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def cleaning_features(data,race):
58
  # with open('race_onehot_encoder.pkl', 'rb') as enc_file:
59
  # encoder = pickle.load(enc_file)
@@ -190,10 +212,18 @@ rf_interface = gr.Interface(
190
  description="Predict income using a Random Forest model."
191
  )
192
 
 
 
 
 
 
 
 
 
193
 
194
  interface = gr.TabbedInterface(
195
- [ann_interface, rf_interface],
196
- ["ANN Model", "Random Forest Model"]
197
  )
198
 
199
 
 
33
  # prediction = 1
34
  return "Income >50K" if prediction == 1 else "Income <=50K"
35
 
36
+ def predict_rf(age, workclass, education, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
37
  # columns = {
38
  # "age": [age], "workclass":[workclass], "educational-num":[education], "marital-status":[marital_status], "occupation":[occupation],
39
  # "relationship":[relationship], "race":[race], "gender":[gender], "capital-gain":[capital_gain], "capital-loss":[capital_loss],
 
54
  # prediction = 1
55
  return "Income >50K" if prediction == 1 else "Income <=50K"
56
 
57
+ def predict_hb(age, workclass, education, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
58
+ # columns = {
59
+ # "age": [age], "workclass":[workclass], "educational-num":[education], "marital-status":[marital_status], "occupation":[occupation],
60
+ # "relationship":[relationship], "race":[race], "gender":[gender], "capital-gain":[capital_gain], "capital-loss":[capital_loss],
61
+ # "hours-per-week":[hours_per_week], "native-country":[native_country]}
62
+ columns = { "0":[0],
63
+ "age": [age], "workclass":[workclass], "educational-num":[education], "occupation":[occupation],
64
+ "race":[race], "gender":[gender], "capital-gain":[capital_gain], "capital-loss":[capital_loss],
65
+ "hours-per-week":[hours_per_week], "native-country":[native_country]}
66
+ df = pd.DataFrame(data=columns)
67
+ fixed_features = cleaning_features(df,race)
68
+ print(fixed_features)
69
+ # with open('ann_model.pkl', 'rb') as ann_model_file:
70
+ # ann_model = pickle.load(ann_model_file)
71
+ scaler = StandardScaler()
72
+ X = scaler.fit_transform(fixed_features)
73
+ hb_model = pickle.load(open('hdbscan_model.pkl', 'rb'))
74
+ prediction = hb_model.predict(fixed_features)
75
+ # prediction = 1
76
+ return "Income >50K" if prediction == 1 else "Income <=50K"
77
+
78
+
79
  def cleaning_features(data,race):
80
  # with open('race_onehot_encoder.pkl', 'rb') as enc_file:
81
  # encoder = pickle.load(enc_file)
 
212
  description="Predict income using a Random Forest model."
213
  )
214
 
215
+ hb_interface = gr.Interface(
216
+ fn=predict_hb,
217
+ inputs=inputs,
218
+ outputs="text",
219
+ title="HDBScan Clustering",
220
+ description="Predict income using a HDBScan Clustering model."
221
+ )
222
+
223
 
224
  interface = gr.TabbedInterface(
225
+ [ann_interface, rf_interface,hb_interface],
226
+ ["ANN Model", "Random Forest Model","HDBScan Model"]
227
  )
228
 
229