Hope-Liang commited on
Commit
f53d6a1
·
1 Parent(s): b0a9f12
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -83,7 +83,6 @@ model_dir = model.download()
83
  model = joblib.load(model_dir + "/incident_model.pkl")
84
 
85
  batch_data = results_df_preprocessed.copy()
86
- batch_data = batch_data[:100]
87
  batch_data.drop(columns=['incident_datetime','incident_category'], inplace=True)
88
  y_pred = model.predict(batch_data)
89
 
@@ -93,11 +92,12 @@ results_df_preprocessed["report_type_code"]=results_df_preprocessed.apply(lambda
93
  results_df_preprocessed.drop(columns=["report_type_code_II","report_type_code_IS","report_type_code_VI","report_type_code_VS"],inplace=True)
94
  results_df_preprocessed["police_district"]=results_df_preprocessed.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)
95
  results_df_preprocessed.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)
 
96
  results_df_preprocessed["idx_temp"]=results_df_preprocessed.index
97
  results_df_preprocessed["incident_category_pred"]=y_pred[results_df_preprocessed.idx_temp]
98
  results_df_preprocessed.drop(columns=["idx_temp"],inplace=True)
99
 
100
- df = results_df_preprocessed
101
 
102
  st.write(df)
103
  st.button("Re-run")
 
83
  model = joblib.load(model_dir + "/incident_model.pkl")
84
 
85
  batch_data = results_df_preprocessed.copy()
 
86
  batch_data.drop(columns=['incident_datetime','incident_category'], inplace=True)
87
  y_pred = model.predict(batch_data)
88
 
 
92
  results_df_preprocessed.drop(columns=["report_type_code_II","report_type_code_IS","report_type_code_VI","report_type_code_VS"],inplace=True)
93
  results_df_preprocessed["police_district"]=results_df_preprocessed.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
  results_df_preprocessed.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
+ results_df_preprocessed.reset_index(inplace=True)
96
  results_df_preprocessed["idx_temp"]=results_df_preprocessed.index
97
  results_df_preprocessed["incident_category_pred"]=y_pred[results_df_preprocessed.idx_temp]
98
  results_df_preprocessed.drop(columns=["idx_temp"],inplace=True)
99
 
100
+ df = results_df_preprocessed[['incident_datetime', 'latitude', 'longitude', 'incident_day_of_week', 'report_type_code', 'police_district', 'incident_category', 'incident_category_pred']]
101
 
102
  st.write(df)
103
  st.button("Re-run")