rscolati commited on
Commit
cc6cf1d
1 Parent(s): cec80b1

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +5 -13
  2. requirements.txt +1 -0
app.py CHANGED
@@ -16,23 +16,14 @@ model_dir = model.download()
16
  model = joblib.load(model_dir + "/titanic_model.pkl")
17
 
18
 
19
- def titanic(age, sex, pclass):
20
  input_list = []
21
 
22
- # Bin input age to bin index of range
23
- if age > 0 and age <= 20:
24
- input_list.append(0)
25
- elif age > 20 and age <= 50:
26
- input_list.append(1)
27
- elif age > 50 and age <= 75:
28
- input_list.append(2)
29
- elif age > 75:
30
- input_list.append(3)
31
- else:
32
- input_list.append(0) # negative age changes to zero
33
-
34
  input_list.append(int(sex)) # value returned by dropdown is index of option selected
35
  input_list.append(int(pclass+1)) # index starts at 0 so increment by 1
 
36
 
37
  print(input_list)
38
  # 'res' is a list of predictions returned as the label.
@@ -59,6 +50,7 @@ demo = gr.Interface(
59
  gr.inputs.Number(default=1, label="Age"),
60
  gr.inputs.Dropdown(choices=["Male", "Female"], type="index", label="Sex"),
61
  gr.inputs.Dropdown(choices=["Class 1","Class 2","Class 3"], type="index", label="Pclass"),
 
62
  ],
63
  outputs=gr.Image(type="pil"))
64
 
 
16
  model = joblib.load(model_dir + "/titanic_model.pkl")
17
 
18
 
19
+ def titanic(age, sex, pclass, embarked):
20
  input_list = []
21
 
22
+ bins = [-np.infty, 20, 25, 30, 40, np.infty] # use same bins as in feature definition!
23
+ input_list.append(int(np.digitize([age], bins)[0]))
 
 
 
 
 
 
 
 
 
 
24
  input_list.append(int(sex)) # value returned by dropdown is index of option selected
25
  input_list.append(int(pclass+1)) # index starts at 0 so increment by 1
26
+ input_list.append(int(embarked))
27
 
28
  print(input_list)
29
  # 'res' is a list of predictions returned as the label.
 
50
  gr.inputs.Number(default=1, label="Age"),
51
  gr.inputs.Dropdown(choices=["Male", "Female"], type="index", label="Sex"),
52
  gr.inputs.Dropdown(choices=["Class 1","Class 2","Class 3"], type="index", label="Pclass"),
53
+ gr.inputs.Dropdown(choices=["S", "C", "Q"], type="index", label="Embarked"),
54
  ],
55
  outputs=gr.Image(type="pil"))
56
 
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  hopsworks
2
  joblib
3
  scikit-learn
 
 
1
  hopsworks
2
  joblib
3
  scikit-learn
4
+ numpy