riyadhrazzaq commited on
Commit
4e8bbcb
Β·
1 Parent(s): a31c8a2

fix l2 norms for officer race, updated models added

Browse files
Files changed (20) hide show
  1. block_officer_gender.py +147 -0
  2. config.py +17 -56
  3. inference.py +3 -3
  4. models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Asian.pkl β†’ ada_undersampling_OfficerRace_Asian.pkl} +2 -2
  5. models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Black.pkl β†’ ada_undersampling_OfficerRace_Black.pkl} +2 -2
  6. models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Hispanic.pkl β†’ ada_undersampling_OfficerRace_Hispanic.pkl} +2 -2
  7. models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_White.pkl β†’ ada_undersampling_OfficerRace_White.pkl} +2 -2
  8. models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Asian.pkl +3 -0
  9. models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Black.pkl +3 -0
  10. models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Hispanic.pkl +3 -0
  11. models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_White.pkl +3 -0
  12. models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Asian.pkl +0 -3
  13. models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Black.pkl +0 -3
  14. models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Hispanic.pkl +0 -3
  15. models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_White.pkl +0 -3
  16. models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Asian.pkl +1 -1
  17. models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Black.pkl +1 -1
  18. models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Hispanic.pkl +1 -1
  19. models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_White.pkl +1 -1
  20. preprocessor.py +21 -14
block_officer_gender.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import config
4
+ import model
5
+ from inference import infer_officer_gender
6
+
7
+
8
+ def infer(model_name,
9
+ current_rank,
10
+ incident_rank,
11
+ previous_complaints,
12
+ complaint_duration_days,
13
+ days_on_force,
14
+ officer_gender,
15
+ fado_type,
16
+ allegation,
17
+ ccrb_disposition,
18
+ penalty_rec,
19
+ penalty_cat,
20
+ location_type,
21
+ contact_outcome,
22
+ impacted_gender,
23
+ impacted_race,
24
+ incident_precinct):
25
+ # throw error if model name is not selected
26
+ if not model_name:
27
+ raise gr.Error("Please select a model")
28
+
29
+ return infer_officer_gender(model_name,
30
+ current_rank,
31
+ incident_rank,
32
+ previous_complaints,
33
+ complaint_duration_days,
34
+ days_on_force,
35
+ officer_gender,
36
+ fado_type,
37
+ allegation,
38
+ ccrb_disposition,
39
+ penalty_rec,
40
+ penalty_cat,
41
+ location_type,
42
+ contact_outcome,
43
+ impacted_gender,
44
+ impacted_race,
45
+ incident_precinct)
46
+
47
+
48
+ with gr.Blocks() as officerGenderDemo:
49
+ with gr.Row():
50
+ with gr.Column():
51
+ current_rank_dropdown = gr.Dropdown(choices=config.features_and_options["CurrentRank"],
52
+ multiselect=False,
53
+ label=config.current_rank_label,
54
+ value=config.features_and_options["CurrentRank"][0])
55
+ incident_rank_dropdown = gr.Dropdown(choices=config.features_and_options["IncidentRank"],
56
+ multiselect=False,
57
+ label=config.incident_rank_label,
58
+ value=config.features_and_options["IncidentRank"][0])
59
+ previous_complaints_slider = gr.Slider(minimum=0,
60
+ maximum=100,
61
+ step=1,
62
+ label=config.previous_complaints_label,
63
+ value=3)
64
+ complaint_duration_days_slider = gr.Slider(minimum=0,
65
+ maximum=100,
66
+ step=1,
67
+ label=config.complaint_duration_days_label,
68
+ value=3)
69
+ days_on_force_slider = gr.Number(label=config.days_on_force_label,
70
+ value=700)
71
+
72
+ officer_gender_dropdown = gr.Dropdown(choices=config.features_and_options["OfficerGender"],
73
+ multiselect=False,
74
+ interactive=True,
75
+ label=config.officer_gender_label,
76
+ value=config.features_and_options["OfficerGender"][0])
77
+ fado_type_dropdown = gr.Dropdown(choices=config.features_and_options["FADOType"],
78
+ multiselect=False,
79
+ label=config.fado_type_label,
80
+ value=config.features_and_options["FADOType"][0])
81
+ allegation_dropdown = gr.Dropdown(choices=config.features_and_options["Allegation"],
82
+ multiselect=False,
83
+ label=config.allegation_label,
84
+ value=config.features_and_options["Allegation"][0])
85
+ with gr.Column():
86
+ ccrb_disposition_dropdown = gr.Dropdown(choices=config.features_and_options["CCRBDisposition"],
87
+ multiselect=False,
88
+ label=config.ccrb_disposition_label,
89
+ value=config.features_and_options["CCRBDisposition"][0])
90
+ penalty_rec_dropdown = gr.Dropdown(choices=config.features_and_options["PenaltyRec"],
91
+ multiselect=False,
92
+ label=config.penalty_rec_label,
93
+ value=config.features_and_options["PenaltyRec"][0])
94
+ penalty_cat_dropdown = gr.Dropdown(choices=config.features_and_options["PenaltyCat"],
95
+ multiselect=False,
96
+ interactive=True,
97
+ label=config.penalty_cat_label,
98
+ value=config.features_and_options["PenaltyCat"][0])
99
+ location_type_dropdown = gr.Dropdown(choices=config.features_and_options["LocationType"],
100
+ multiselect=False,
101
+ label=config.location_type_label,
102
+ value=config.features_and_options["LocationType"][0])
103
+ contact_outcome_dropdown = gr.Dropdown(choices=config.features_and_options["ContactOutcome"],
104
+ multiselect=False,
105
+ label=config.contact_outcome_label,
106
+ value=config.features_and_options["ContactOutcome"][0])
107
+
108
+ impacted_gender_dropdown = gr.Dropdown(choices=config.features_and_options["ImpactedGender"],
109
+ multiselect=False,
110
+ label=config.impacted_gender_label,
111
+ value=config.features_and_options["ImpactedGender"][0])
112
+ impacted_race_dropdown = gr.Dropdown(choices=config.features_and_options["ImpactedRace"],
113
+ multiselect=False,
114
+ label=config.impacted_race_label,
115
+ value=config.features_and_options["ImpactedRace"][0])
116
+ incident_precinct_dropdown = gr.Dropdown(choices=config.features_and_options["IncidentPrecinct"],
117
+ multiselect=False,
118
+ label=config.incident_precinct_label,
119
+ value=config.features_and_options["IncidentPrecinct"][0])
120
+
121
+ with gr.Row():
122
+ with gr.Column():
123
+ model_dropdown = gr.Dropdown(choices=model.available_models("OfficerRace"),
124
+ multiselect=False,
125
+ label=config.model_label)
126
+
127
+ out = gr.Textbox(label="Prediction")
128
+
129
+ input_components = [model_dropdown,
130
+ current_rank_dropdown,
131
+ incident_rank_dropdown,
132
+ previous_complaints_slider,
133
+ complaint_duration_days_slider,
134
+ days_on_force_slider,
135
+ officer_gender_dropdown,
136
+ fado_type_dropdown,
137
+ allegation_dropdown,
138
+ ccrb_disposition_dropdown,
139
+ penalty_rec_dropdown,
140
+ penalty_cat_dropdown,
141
+ location_type_dropdown,
142
+ contact_outcome_dropdown,
143
+ impacted_gender_dropdown,
144
+ impacted_race_dropdown,
145
+ incident_precinct_dropdown]
146
+ btn = gr.Button("Predict")
147
+ btn.click(fn=infer, inputs=input_components, outputs=out)
config.py CHANGED
@@ -64,9 +64,23 @@ features_and_options = {
64
  }
65
 
66
  # todo update this values
67
- officer_race_previous_complaints_l2_norm = 100.0
68
- officer_race_complaint_duration_days_l2_norm = 100.0
69
- officer_race_days_on_force_l2_norm = 100.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  # labels
72
  model_label = "Choose a model"
@@ -88,56 +102,3 @@ contact_outcome_label = "Contact Outcome"
88
  impacted_gender_label = "Impacted Person's Gender"
89
  impacted_race_label = "Impacted Person's Race"
90
  incident_precinct_label = "Incident Precinct"
91
-
92
- ### input feature order
93
- # ['CurrentRank', 'IncidentRank', 'DaysOnForce', 'previousComplaints', 'complaintDurationDays',
94
- # 'OfficerGender_Female', 'OfficerGender_Male', 'OfficerGender_TGNC / Other', 'FADOType_Abuse of Authority',
95
- # 'FADOType_Bias-Based Policing', 'FADOType_Discourtesy', 'FADOType_Force', 'FADOType_Offensive Language',
96
- # 'FADOType_Untruthful Statement', 'Allegation_Action', 'Allegation_Beat', 'Allegation_Black',
97
- # 'Allegation_Chokehold', 'Allegation_Curse', 'Allegation_Demeanor/tone', 'Allegation_Dragged/Pulled',
98
- # 'Allegation_Entry of Premises', 'Allegation_Failure to provide RTKA card', 'Allegation_Forcible Removal to
99
- # Hospital', 'Allegation_Frisk', 'Allegation_Frisk and/or search', 'Allegation_Gun Drawn', 'Allegation_Gun pointed',
100
- # 'Allegation_Hit against inanimate object', 'Allegation_Nasty Words', 'Allegation_Nightstick as club (incl asp &
101
- # baton)', 'Allegation_Nightstick/Billy/Club', 'Allegation_Other', 'Allegation_Other - Abuse', 'Allegation_Other -
102
- # Force', 'Allegation_Other- Discourtesy', 'Allegation_Pepper spray', 'Allegation_Person Searched',
103
- # 'Allegation_Physical force', 'Allegation_Premise Searched', 'Allegation_Premises entered and/or searched',
104
- # 'Allegation_Property damaged', 'Allegation_Punch/Kick', 'Allegation_Push/Shove', 'Allegation_Question',
105
- # 'Allegation_Question and/or stop', 'Allegation_Race', 'Allegation_Refusal to obtain medical treatment',
106
- # 'Allegation_Refusal to process civilian complaint', 'Allegation_Refusal to provide name', 'Allegation_Refusal to
107
- # provide name/shield number', 'Allegation_Refusal to provide shield number', 'Allegation_Retaliatory summons',
108
- # 'Allegation_Search (of person)', 'Allegation_Search of Premises', 'Allegation_Seizure of property',
109
- # 'Allegation_Slap', 'Allegation_Stop', 'Allegation_Strip-searched', 'Allegation_Threat of arrest',
110
- # 'Allegation_Threat of force', 'Allegation_Threat of force (verbal or physical)', 'Allegation_Threat of summons',
111
- # 'Allegation_Threat to damage/seize property', 'Allegation_Vehicle search', 'Allegation_Vehicle stop',
112
- # 'Allegation_Word', 'CCRBDisposition_Alleged Victim Unavailable', 'CCRBDisposition_Alleged Victim Uncooperative',
113
- # 'CCRBDisposition_Closed - Pending Litigation', 'CCRBDisposition_Complainant Unavailable',
114
- # 'CCRBDisposition_Complainant Uncooperative', 'CCRBDisposition_Complaint Withdrawn', 'CCRBDisposition_Exonerated',
115
- # 'CCRBDisposition_Miscellaneous', 'CCRBDisposition_Miscellaneous - Subject Resigned', 'CCRBDisposition_Miscellaneous
116
- # - Subject Retired', 'CCRBDisposition_Miscellaneous - Subject Terminated', 'CCRBDisposition_Substantiated (
117
- # Charges)', 'CCRBDisposition_Substantiated (Command Discipline A)', 'CCRBDisposition_Substantiated (Command
118
- # Discipline B)', 'CCRBDisposition_Substantiated (Command Discipline)', 'CCRBDisposition_Substantiated (Command Lvl
119
- # Instructions)', 'CCRBDisposition_Substantiated (Formalized Training)', 'CCRBDisposition_Substantiated (
120
- # Instructions)', 'CCRBDisposition_Substantiated (MOS Unidentified)', 'CCRBDisposition_Substantiated (No
121
- # Recommendations)', 'CCRBDisposition_Unable to Determine', 'CCRBDisposition_Unfounded',
122
- # 'CCRBDisposition_Unsubstantiated', 'CCRBDisposition_Victim Unidentified', 'CCRBDisposition_Within NYPD Guidelines',
123
- # 'CCRBDisposition_Witness Unavailable', 'CCRBDisposition_Witness Uncooperative', 'PenaltyRec_Substantiated (
124
- # Charges)', 'PenaltyRec_Substantiated (Command Discipline A)', 'PenaltyRec_Substantiated (Command Discipline B)',
125
- # 'PenaltyRec_Substantiated (Command Discipline)', 'PenaltyRec_Substantiated (Formalized Training)',
126
- # 'PenaltyRec_Substantiated (Instructions)', 'PenaltyRec_Substantiated (MOS Unidentified)', 'PenaltyRec_Substantiated
127
- # (No Recommendations)', 'PenaltyRec_Unknown', 'PenaltyCat_Command Discipline', 'PenaltyCat_Loss of vacation',
128
- # 'PenaltyCat_No discipline', 'PenaltyCat_Pending', 'PenaltyCat_Probation', 'PenaltyCat_Reprimand',
129
- # 'PenaltyCat_Resigned/Retired', 'PenaltyCat_Suspension', 'PenaltyCat_Termination', 'LocationType_Apartment/house',
130
- # 'LocationType_Bus', 'LocationType_Commercial building', 'LocationType_Hospital', 'LocationType_NYCHA',
131
- # 'LocationType_Other', 'LocationType_Park', 'LocationType_Police building', 'LocationType_Police vehicle',
132
- # 'LocationType_Public space/building', 'LocationType_Residential building', 'LocationType_River or waterway',
133
- # 'LocationType_School', 'LocationType_Street/highway', 'LocationType_Subway station/train', 'LocationType_Unknown',
134
- # 'ContactOutcome_Arrest', 'ContactOutcome_No arrest made or summons issued', 'ContactOutcome_Summons',
135
- # 'ContactOutcome_Unknown', 'ImpactedGender_Female', 'ImpactedGender_Male', 'ImpactedGender_TGNC / Other',
136
- # 'ImpactedGender_Unknown', 'ImpactedRace_American Indian', 'ImpactedRace_Asian', 'ImpactedRace_Black',
137
- # 'ImpactedRace_Hispanic', 'ImpactedRace_Other Race', 'ImpactedRace_Refused', 'ImpactedRace_Unknown',
138
- # 'ImpactedRace_White', 'IncidentPrecinct_Bronx', 'IncidentPrecinct_Brooklyn North', 'IncidentPrecinct_Brooklyn
139
- # South', 'IncidentPrecinct_Manhattan North', 'IncidentPrecinct_Manhattan South', 'IncidentPrecinct_Queens North',
140
- # 'IncidentPrecinct_Queens South', 'IncidentPrecinct_Staten Island']
141
- #
142
- # Index(['OfficerRace_Asian', 'OfficerRace_Black',
143
- # 'OfficerRace_Hispanic', 'OfficerRace_White'], dtype='object')
 
64
  }
65
 
66
  # todo update this values
67
+ # Undersampling
68
+ officer_race_l2_norm = {
69
+ "undersampling": {
70
+ "days_on_force": 584626.6887151151,
71
+ "complaint_duration_days": 51802.459555507594,
72
+ "previous_complaints": 1638.7052816171674,
73
+ "current_rank": 566.5465558981009,
74
+ "incident_rank": 440.99886621169446
75
+ },
76
+ "no_undersampling": {
77
+ "days_on_force": 1601408.5087007,
78
+ "complaint_duration_days": 132675.77404334222,
79
+ "previous_complaints": 4305.6496606203345,
80
+ "current_rank": 1539.0136451636808,
81
+ "incident_rank": 1196.2131917012118
82
+ }
83
+ }
84
 
85
  # labels
86
  model_label = "Choose a model"
 
102
  impacted_gender_label = "Impacted Person's Gender"
103
  impacted_race_label = "Impacted Person's Race"
104
  incident_precinct_label = "Incident Precinct"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inference.py CHANGED
@@ -2,7 +2,7 @@ import numpy as np
2
 
3
  import config
4
  from model import load_models
5
- from preprocessor import process_officer_race
6
 
7
 
8
  def predict_officer_race(model_name, X):
@@ -21,7 +21,7 @@ def infer_officer_race(model_name, current_rank, incident_rank, previous_complai
21
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
22
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
23
  incident_precinct):
24
- input_array = process_officer_race(current_rank, incident_rank, previous_complaints, complaint_duration_days,
25
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
26
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
27
  incident_precinct)
@@ -34,7 +34,7 @@ def infer_officer_gender(model_name, current_rank, incident_rank, previous_compl
34
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
35
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
36
  incident_precinct):
37
- input_array = process_officer_race(current_rank, incident_rank, previous_complaints, complaint_duration_days,
38
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
39
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
40
  incident_precinct)
 
2
 
3
  import config
4
  from model import load_models
5
+ from preprocessor import process_officer_race, process_officer_gender
6
 
7
 
8
  def predict_officer_race(model_name, X):
 
21
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
22
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
23
  incident_precinct):
24
+ input_array = process_officer_race(model_name,current_rank, incident_rank, previous_complaints, complaint_duration_days,
25
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
26
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
27
  incident_precinct)
 
34
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
35
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
36
  incident_precinct):
37
+ input_array = process_officer_gender(current_rank, incident_rank, previous_complaints, complaint_duration_days,
38
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
39
  penalty_rec, penalty_cat, location_type, contact_outcome, impacted_gender, impacted_race,
40
  incident_precinct)
models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Asian.pkl β†’ ada_undersampling_OfficerRace_Asian.pkl} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5938b672055afcc013873a2e2fa7b907f4ba9503d9d0d0a506a62d2545df366b
3
- size 1856036
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c10588bcab2d11f1a2692421f8b9cc3034184990223d8f936d1b2e6ff76d86c
3
+ size 1912628
models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Black.pkl β†’ ada_undersampling_OfficerRace_Black.pkl} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad083343f12c479fb9510467f98181604daa4fb7061f2ada1dca1a070b48626c
3
- size 3000404
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd3a4d92badf05908acff487914d60d0b1e4f7d8c4ddd96faa8e978d0e103184
3
+ size 4120436
models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_Hispanic.pkl β†’ ada_undersampling_OfficerRace_Hispanic.pkl} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b973e31937e42e1bbdac28db5bcced0d342e4f7f2993daf90cad379dd8509ff2
3
- size 2448164
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a714d2af5c26e700e39ac8e7913fa801402f5de6ff817567c5f263034df69e1
3
+ size 2582228
models/OfficerRace/ADA Undersampling/{ada_undersampling__OfficerRace_White.pkl β†’ ada_undersampling_OfficerRace_White.pkl} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:744428aa96f9c824939054cf643be475e58970e20705e1237f850f9465eadea0
3
- size 3244916
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7ac862e8729d1ab0769b24c16a8c70db6a2bfac08f43f2b359f7520985911b3
3
+ size 5265668
models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Asian.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4386382127471778e9f2b0204b3ee1bbd1527e8a8c8e9d305d64b40e8e56357
3
+ size 832793
models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Black.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b79f0d27fe31d3867c2a97254b9eb2f427d5e54a12f36fcf44ae049a44f033ff
3
+ size 954329
models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_Hispanic.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6de17b0b32654d61b5a0b8bc3aa25d1aa777f56bbc963bb866008b085595a1ac
3
+ size 1064633
models/OfficerRace/Decision Tree Undersampling/dt_undersampling_OfficerRace_White.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d2e0eda9284b85febbc247796795ea2d181e14ce965faefc6449b090aba05fe
3
+ size 933161
models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Asian.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:34a707091f94272edf56bedfb24994b0b8d7c9afd1a7d168c0627054f933c8e1
3
- size 6278571
 
 
 
 
models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Black.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ce31414991aeaeb5b66137175f368e7b79fa438e3222e8e747f42f22a9dbef38
3
- size 6598014
 
 
 
 
models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_Hispanic.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6b6bfe15aa59e21b28fcf9c663e8e08ce4b7bd9f3f09a39ae8cf37ef0eebdc0d
3
- size 6630474
 
 
 
 
models/OfficerRace/GB Undersampling/gb_undersampling_OfficerRace_White.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6b5c2994e14db4499042a87e7c5e20515e6a29cfcfc51dd7bfc82ea9bf66a9d8
3
- size 6599854
 
 
 
 
models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Asian.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f993447cca64f5280ff39a1fd7bf6795a7b82e180ab92d81b1a8782ab05207b7
3
  size 2079
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4da8179e585bff1b317e3723f2859affa19a438b6d8a2b91dc0a90d2ebe19316
3
  size 2079
models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Black.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ca50af63aae1e30e35ca2cfd9a834121d5d9dd64c34c4eb7322acb6d1cd3fd07
3
  size 2079
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d40da619b2419b8d61ca40f1a5e4e57828c75ac93ae33e44d5c39ba2cefbae5a
3
  size 2079
models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_Hispanic.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d8419d5775699d928ebc525679badd9903d29dc2bc468c6ceb876b7dbf7592ef
3
  size 2079
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27f06d2feb2a65c6fdd2afdd46d316b93bd0eb0717ef7cf1afd7d649cf4c8a06
3
  size 2079
models/OfficerRace/{Logistic Regression β†’ Logistic Regression Undersampling}/lr_undersampling_OfficerRace_White.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:fe720f754746a114a6e507aa6cb3a362d6d8bb5adc6cc3ac5b5265fa153b7c2b
3
  size 2079
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f8adbf9f30af073454fb50b522c4461d317781210b117574bdc189d7c70c5bd
3
  size 2079
preprocessor.py CHANGED
@@ -48,25 +48,29 @@ rank_to_ordinal = {
48
  }
49
 
50
 
51
- def transform_rank(current_rank):
52
- return np.array((rank_to_ordinal[current_rank], ))
53
 
54
 
55
- def transform_previous_complaints(previous_complaints):
 
 
 
 
56
  x = int(previous_complaints)
57
- x = x / config.officer_race_previous_complaints_l2_norm
58
  return np.array((x, ))
59
 
60
 
61
- def transform_complaint_duration_days(complaint_duration_days):
62
  x = int(complaint_duration_days)
63
- x = x / config.officer_race_complaint_duration_days_l2_norm
64
  return np.array((x, ))
65
 
66
 
67
- def transform_days_on_force(days_on_force):
68
  x = int(days_on_force)
69
- x = x / config.officer_race_days_on_force_l2_norm
70
  return np.array((x, ))
71
 
72
 
@@ -77,16 +81,19 @@ def transform_to_ohe(column_name, value):
77
  return one_hot
78
 
79
 
80
- def process_officer_race(current_rank, incident_rank, previous_complaints, complaint_duration_days,
81
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
82
  penalty_rec, penalty_cat, location_type, contact_outcome,
83
  impacted_gender, impacted_race,
84
  incident_precinct):
85
- current_rank = transform_rank(current_rank)
86
- incident_rank = transform_rank(incident_rank)
87
- previous_complaints = transform_previous_complaints(previous_complaints)
88
- complaint_duration_days = transform_complaint_duration_days(complaint_duration_days)
89
- days_on_force = transform_days_on_force(days_on_force)
 
 
 
90
  officer_gender = transform_to_ohe('OfficerGender', officer_gender)
91
  fado_type = transform_to_ohe('FADOType', fado_type)
92
  allegation = transform_to_ohe('Allegation', allegation)
 
48
  }
49
 
50
 
51
+ def transform_incident_rank(l2_norms, incident_rank):
52
+ return np.array((rank_to_ordinal[incident_rank] / l2_norms["incident_rank"], ))
53
 
54
 
55
+ def transform_current_rank(l2_norms, current_rank):
56
+ return np.array((rank_to_ordinal[current_rank] / l2_norms["current_rank"], ))
57
+
58
+
59
+ def transform_previous_complaints(l2_norms, previous_complaints):
60
  x = int(previous_complaints)
61
+ x = x / l2_norms["previous_complaints"]
62
  return np.array((x, ))
63
 
64
 
65
+ def transform_complaint_duration_days(l2_norms, complaint_duration_days):
66
  x = int(complaint_duration_days)
67
+ x = x / l2_norms["complaint_duration_days"]
68
  return np.array((x, ))
69
 
70
 
71
+ def transform_days_on_force(l2_norms, days_on_force):
72
  x = int(days_on_force)
73
+ x = x / l2_norms["days_on_force"]
74
  return np.array((x, ))
75
 
76
 
 
81
  return one_hot
82
 
83
 
84
+ def process_officer_race(model_name, current_rank, incident_rank, previous_complaints, complaint_duration_days,
85
  days_on_force, officer_gender, fado_type, allegation, ccrb_disposition,
86
  penalty_rec, penalty_cat, location_type, contact_outcome,
87
  impacted_gender, impacted_race,
88
  incident_precinct):
89
+ l2_norms = config.officer_race_l2_norm['undersampling' if 'Undersampling' in model_name else 'no_undersampling']
90
+
91
+ current_rank = transform_current_rank(l2_norms, current_rank)
92
+ incident_rank = transform_incident_rank(l2_norms, incident_rank)
93
+ previous_complaints = transform_previous_complaints(l2_norms, previous_complaints)
94
+ complaint_duration_days = transform_complaint_duration_days(l2_norms, complaint_duration_days)
95
+ days_on_force = transform_days_on_force(l2_norms, days_on_force)
96
+
97
  officer_gender = transform_to_ohe('OfficerGender', officer_gender)
98
  fado_type = transform_to_ohe('FADOType', fado_type)
99
  allegation = transform_to_ohe('Allegation', allegation)