Hope-Liang commited on
Commit
4e27464
·
1 Parent(s): 953bc5b
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -23,6 +23,45 @@ def unencode_weekday(fri, mon, sat, sun, thu, tue, wed):
23
  else:
24
  return "Invalid Weekday"
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  st.set_page_config(layout="wide")
27
  st.title('Latest SF Incident Category Prediction')
28
 
@@ -49,7 +88,10 @@ 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
 
 
23
  else:
24
  return "Invalid Weekday"
25
 
26
+ def unencode_report_type_code(ii, iss, vi, vs):
27
+ if ii==1.0:
28
+ return "II"
29
+ elif iss==1.0:
30
+ return "IS"
31
+ elif vi==1.0:
32
+ return "VI"
33
+ elif vs==1.0:
34
+ return "VS"
35
+ else:
36
+ return "Invalid Report Type Code"
37
+
38
+ def unencode_police_district(bay, cen, ing, mis, nor, out, par, ric, sou, tar, ten):
39
+ if bay==1.0:
40
+ return "Bayview"
41
+ elif cen==1.0:
42
+ return "Central"
43
+ elif ing==1.0:
44
+ return "Ingleside"
45
+ elif mis==1.0:
46
+ return "Mission"
47
+ elif nor==1.0:
48
+ return "Northern"
49
+ elif out==1.0:
50
+ return "OutOfSF"
51
+ elif par==1.0:
52
+ return "Park"
53
+ elif ric==1.0:
54
+ return "Richmond"
55
+ elif sou==1.0:
56
+ return "Southern"
57
+ elif tar==1.0:
58
+ return "Taraval"
59
+ elif ten==1.0:
60
+ return "Tenderloin"
61
+ else:
62
+ return "Invalid Police District"
63
+
64
+
65
  st.set_page_config(layout="wide")
66
  st.title('Latest SF Incident Category Prediction')
67
 
 
88
 
89
  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)
90
  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)
91
+ batch_data["report_type_code"]=batch_data.apply(lambda x:unencode_report_type_code(x.report_type_code_II,x.report_type_code_IS,x.report_type_code_VI,x.report_type_code_VS),axis=1)
92
+ batch_data.drop(columns=["report_type_code_II","report_type_code_IS","report_type_code_VI","report_type_code_VS"],inplace=True)
93
+ batch_data["police_district"]=batch_data.apply(lambda x:unencode_police_district(x.police_district_Bayview,x.police_district_Central,x.police_district_Ingleside,x.police_district_Mission,x.police_district_Northern,x.police_district_OutOfSF,x.police_district_Park,x.police_district_Richmond,x.police_district_Southern,x.police_district_Taraval,x.police_district_Tenderloin),axis=1)
94
+ batch_data.drop(columns=["police_district_Bayview","police_district_Central","police_district_Ingleside","police_district_Mission","police_district_Northern","police_district_OutOfSF","police_district_Park","police_district_Richmond","police_district_Southern","police_district_Taraval","police_district_Tenderloin"],inplace=True)
95
 
96
  df = batch_data
97