Spaces:
Runtime error
Runtime error
Hope-Liang
commited on
Commit
·
953bc5b
1
Parent(s):
996c04d
update
Browse files
app.py
CHANGED
@@ -5,9 +5,26 @@ import hopsworks
|
|
5 |
import joblib
|
6 |
import xgboost as xgb
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
st.set_page_config(layout="wide")
|
10 |
-
st.title('Latest SF
|
11 |
|
12 |
client = Socrata("data.sfgov.org", "gZmg4iarmENBTk1Vzsb94bnse", username="[email protected]", password="Xw990504")
|
13 |
results = client.get("wg3w-h783", limit=800000)
|
@@ -17,7 +34,7 @@ from preprocessor_pipeline import preprocessing_incident
|
|
17 |
results_df_preprocessed = preprocessing_incident(results_df)
|
18 |
results_df_preprocessed.incident_datetime=pd.to_datetime(results_df_preprocessed.incident_datetime)
|
19 |
results_df_preprocessed.sort_values(by='incident_datetime', ascending = False, inplace = True)
|
20 |
-
results_df_preprocessed=results_df_preprocessed[:100]
|
21 |
|
22 |
project = hopsworks.login()
|
23 |
fs = project.get_feature_store()
|
@@ -30,7 +47,11 @@ batch_data = results_df_preprocessed
|
|
30 |
batch_data.drop(columns=['incident_datetime','incident_category'], inplace=True)
|
31 |
y_pred = model.predict(batch_data)
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
|
35 |
st.write(df)
|
36 |
st.button("Re-run")
|
|
|
5 |
import joblib
|
6 |
import xgboost as xgb
|
7 |
|
8 |
+
def unencode_weekday(fri, mon, sat, sun, thu, tue, wed):
|
9 |
+
if fri==1.0:
|
10 |
+
return "Friday"
|
11 |
+
elif mon==1.0:
|
12 |
+
return "Monday"
|
13 |
+
elif sat==1.0:
|
14 |
+
return "Saturday"
|
15 |
+
elif sun==1.0:
|
16 |
+
return "Sunday"
|
17 |
+
elif thu==1.0:
|
18 |
+
return "Thursday"
|
19 |
+
elif tue==1.0:
|
20 |
+
return "Tuesday"
|
21 |
+
elif wed==1.0:
|
22 |
+
return "Wednesday"
|
23 |
+
else:
|
24 |
+
return "Invalid Weekday"
|
25 |
|
26 |
st.set_page_config(layout="wide")
|
27 |
+
st.title('Latest SF Incident Category Prediction')
|
28 |
|
29 |
client = Socrata("data.sfgov.org", "gZmg4iarmENBTk1Vzsb94bnse", username="[email protected]", password="Xw990504")
|
30 |
results = client.get("wg3w-h783", limit=800000)
|
|
|
34 |
results_df_preprocessed = preprocessing_incident(results_df)
|
35 |
results_df_preprocessed.incident_datetime=pd.to_datetime(results_df_preprocessed.incident_datetime)
|
36 |
results_df_preprocessed.sort_values(by='incident_datetime', ascending = False, inplace = True)
|
37 |
+
results_df_preprocessed = results_df_preprocessed[:100]
|
38 |
|
39 |
project = hopsworks.login()
|
40 |
fs = project.get_feature_store()
|
|
|
47 |
batch_data.drop(columns=['incident_datetime','incident_category'], inplace=True)
|
48 |
y_pred = model.predict(batch_data)
|
49 |
|
50 |
+
batch_data["incident_day_of_week"]=batch_data.apply(lambda x:unencode_weekday(x.incident_day_of_week_Friday,x.incident_day_of_week_Monday,x.incident_day_of_week_Saturday,x.incident_day_of_week_Sunday,x.incident_day_of_week_Thursday,x.incident_day_of_week_Tuesday,x.incident_day_of_week_Wednesday),axis=1)
|
51 |
+
batch_data.drop(columns=["incident_day_of_week_Friday","incident_day_of_week_Monday","incident_day_of_week_Saturday","incident_day_of_week_Sunday","incident_day_of_week_Thursday","incident_day_of_week_Tuesday","incident_day_of_week_Wednesday"],inplace=True)
|
52 |
+
|
53 |
+
|
54 |
+
df = batch_data
|
55 |
|
56 |
st.write(df)
|
57 |
st.button("Re-run")
|