Spaces:
Sleeping
Sleeping
Commit
·
692bcda
1
Parent(s):
57fcd83
Fix Custom Prediciton
Browse files
app.py
CHANGED
@@ -88,15 +88,18 @@ st.write("Enter your own values for prediction:")
|
|
88 |
selected_features = ["INITIAL_CALL_TYPE", "INITIAL_SEVERITY_LEVEL_CODE", "INCIDENT_DATETIME", "INCIDENT_CLOSE_DATETIME", "ZIPCODE", "POLICEPRECINCT", "FINAL_CALL_TYPE"]
|
89 |
feature_inputs = {}
|
90 |
for feature in selected_features:
|
91 |
-
if feature
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
|
98 |
# encode user input
|
99 |
-
user_data = encode(
|
100 |
|
101 |
if st.button("Predict"):
|
102 |
t1 = time.time() * 1000
|
@@ -104,8 +107,7 @@ if st.button("Predict"):
|
|
104 |
t2 = time.time() * 1000
|
105 |
|
106 |
st.write("Predicted Call Type:", predicted_label)
|
107 |
-
st.
|
108 |
-
|
109 |
|
110 |
st.header("Results")
|
111 |
st.markdown(
|
|
|
88 |
selected_features = ["INITIAL_CALL_TYPE", "INITIAL_SEVERITY_LEVEL_CODE", "INCIDENT_DATETIME", "INCIDENT_CLOSE_DATETIME", "ZIPCODE", "POLICEPRECINCT", "FINAL_CALL_TYPE"]
|
89 |
feature_inputs = {}
|
90 |
for feature in selected_features:
|
91 |
+
if feature in ['INITIAL_CALL_TYPE', 'DAY_OF_WEEK', 'POLICEPRECINCT', 'ZIPCODE']: # categorical
|
92 |
+
options = list(sample_data[feature].unique())
|
93 |
+
else: # numerical
|
94 |
+
options = [str(x) for x in sample_data[feature].unique()]
|
95 |
+
feature_inputs[feature] = st.selectbox(feature, options=options)
|
96 |
+
|
97 |
+
custom_params = pd.Series(feature_inputs)
|
98 |
+
|
99 |
+
print(custom_params);
|
100 |
|
101 |
# encode user input
|
102 |
+
user_data = encode(custom_params)
|
103 |
|
104 |
if st.button("Predict"):
|
105 |
t1 = time.time() * 1000
|
|
|
107 |
t2 = time.time() * 1000
|
108 |
|
109 |
st.write("Predicted Call Type:", predicted_label)
|
110 |
+
st.success(f"""Label successfully predicted in {t2-t1:.2f}ms!""")
|
|
|
111 |
|
112 |
st.header("Results")
|
113 |
st.markdown(
|
model.py
CHANGED
@@ -15,6 +15,8 @@ def encode(data):
|
|
15 |
params['INCIDENT_DATETIME'] = pd.to_datetime(params['INCIDENT_DATETIME'])
|
16 |
params['INCIDENT_CLOSE_DATETIME'] = pd.to_datetime(params['INCIDENT_CLOSE_DATETIME'])
|
17 |
|
|
|
|
|
18 |
params['DAY_OF_WEEK'] = params['INCIDENT_DATETIME'].dayofweek
|
19 |
params['INCIDENT_HOUR'] = params['INCIDENT_DATETIME'].hour
|
20 |
params['INCIDENT_DURATION'] = (params['INCIDENT_CLOSE_DATETIME'] - params['INCIDENT_DATETIME']).total_seconds()
|
@@ -32,4 +34,4 @@ def predict(params):
|
|
32 |
return res[0]
|
33 |
except Exception as e:
|
34 |
print(e)
|
35 |
-
return "error"
|
|
|
15 |
params['INCIDENT_DATETIME'] = pd.to_datetime(params['INCIDENT_DATETIME'])
|
16 |
params['INCIDENT_CLOSE_DATETIME'] = pd.to_datetime(params['INCIDENT_CLOSE_DATETIME'])
|
17 |
|
18 |
+
print(type(params['INCIDENT_CLOSE_DATETIME']))
|
19 |
+
|
20 |
params['DAY_OF_WEEK'] = params['INCIDENT_DATETIME'].dayofweek
|
21 |
params['INCIDENT_HOUR'] = params['INCIDENT_DATETIME'].hour
|
22 |
params['INCIDENT_DURATION'] = (params['INCIDENT_CLOSE_DATETIME'] - params['INCIDENT_DATETIME']).total_seconds()
|
|
|
34 |
return res[0]
|
35 |
except Exception as e:
|
36 |
print(e)
|
37 |
+
return "error"
|