This is our the color scheme we used for the whole document:
From our data we decided to look at factors that affected stop outcome and stop type.
Our factors:
Gender: Male, Female, Other
Races: Black, Asian, Hispanic, White
Stop Type: Moving Violation (speeding, illegal turns), Investigatory (suspected drugs or weapons), Susp DUI (driving while under the influence), Equipment (lights, tags, license plates, etc…), Other, External
Stop_Outcome: Warning, Ticket, Arrest, No Action
## # A tibble: 29,583 × 11
## year month weekday hour minute race gender age stop_type stop_outcome
## <dbl> <dbl> <ord> <int> <int> <chr> <chr> <int> <chr> <chr>
## 1 2012 1 Wed 14 43 White Female 23 Moving Viol… Warning
## 2 2012 1 Sun 0 18 White Female 73 Equipment Warning
## 3 2012 1 Sun 0 18 White Male 25 Susp DUI Warning
## 4 2012 1 Sun 8 50 White Female 23 Equipment Warning
## 5 2012 1 Sun 8 56 White Female 17 Other Warning
## 6 2012 1 Sun 9 4 White Male 47 Equipment Warning
## 7 2012 1 Wed 14 50 White Female 29 Equipment Ticket
## 8 2012 1 Wed 15 13 White Male 28 Moving Viol… Warning
## 9 2012 1 Sun 9 19 White Female 34 Equipment Warning
## 10 2012 1 Sun 10 27 White Male 23 Moving Viol… Warning
## # ℹ 29,573 more rows
## # ℹ 1 more variable: time <dbl>
| Total Amount of Each Outcomes | ||
| Arrest | Ticket | Warning |
|---|---|---|
| 106 | 7003 | 22424 |
## # A tibble: 24 × 5
## race total type value percent
## <chr> <int> <chr> <int> <dbl>
## 1 Asian 1278 speeding 783 0.613
## 2 Asian 1278 vehicle_issues 440 0.344
## 3 Asian 1278 external 0 0
## 4 Asian 1278 other 24 0.0188
## 5 Asian 1278 DUI 8 0.00626
## 6 Asian 1278 investigatory 7 0.00548
## 7 Black 2488 speeding 1351 0.543
## 8 Black 2488 vehicle_issues 984 0.395
## 9 Black 2488 external 0 0
## 10 Black 2488 other 79 0.0318
## # ℹ 14 more rows
In our further exploration of our traffic stops data, we are going to use machine learning to see if we can predict the gender of the individual, based on the stop type, race, and age. Our other technique focused on stopping outcomes based on age and time.
Our first method is going to be making a classification tree. This method is going to look at gender based on stop type, race, and age.
## CP nsplit rel error xerror xstd
## 1 0.0018899 0 1.0000 1.000 0.02328
## 2 0.0015564 9 0.9829 1.001 0.02329
## 3 0.0007782 12 0.9782 1.002 0.02329
## 4 0.0005188 22 0.9704 1.017 0.02339
## 5 0.0003891 25 0.9689 1.017 0.02339
## 6 0.0002594 31 0.9665 1.017 0.02339
## 7 0.0001556 40 0.9642 1.014 0.02337
## 8 0.0000000 45 0.9634 1.015 0.02338
## 9 -1.0000000 104 0.9634 1.015 0.02338
## xerror cutoff cp prune value
## 1.02328 0.00189
## Overall
## age_range 54.35
## race 62.30
## stop_type 62.60
## Overall
## stop_type 0
## race 0
## age_range 0
## gender Fem Mal Oth
## Male [.30 .70 .00] null model
Using KNN Classification we are hoping to predict stop outcomes by time and age.
## # A tibble: 28,992 × 11
## year month weekday hour minute race gender age stop_type time outcome
## <dbl> <dbl> <ord> <int> <int> <chr> <chr> <int> <chr> <dbl> <fct>
## 1 2012 1 Wed 14 43 White Female 23 Moving Vio… 883 0
## 2 2012 1 Sun 0 18 White Female 73 Equipment 18 0
## 3 2012 1 Sun 0 18 White Male 25 Susp DUI 18 0
## 4 2012 1 Sun 8 50 White Female 23 Equipment 530 0
## 5 2012 1 Sun 8 56 White Female 17 Other 536 0
## 6 2012 1 Sun 9 4 White Male 47 Equipment 544 0
## 7 2012 1 Wed 14 50 White Female 29 Equipment 890 1
## 8 2012 1 Wed 15 13 White Male 28 Moving Vio… 913 0
## 9 2012 1 Sun 9 19 White Female 34 Equipment 559 0
## 10 2012 1 Sun 10 27 White Male 23 Moving Vio… 627 0
## # ℹ 28,982 more rows
## # A tibble: 28,992 × 11
## year month weekday hour minute race gender age stop_type time outcome
## <dbl> <dbl> <ord> <int> <int> <chr> <chr> <dbl> <chr> <dbl> <fct>
## 1 2012 1 Wed 14 43 White Female 0.204 Moving Vi… 0.614 0
## 2 2012 1 Sun 0 18 White Female 0.337 Equipment 0.0125 0
## 3 2012 1 Sun 0 18 White Male 0.210 Susp DUI 0.0125 0
## 4 2012 1 Sun 8 50 White Female 0.204 Equipment 0.368 0
## 5 2012 1 Sun 8 56 White Female 0.188 Other 0.372 0
## 6 2012 1 Sun 9 4 White Male 0.268 Equipment 0.378 0
## 7 2012 1 Wed 14 50 White Female 0.220 Equipment 0.618 1
## 8 2012 1 Wed 15 13 White Male 0.218 Moving Vi… 0.634 0
## 9 2012 1 Sun 9 19 White Female 0.233 Equipment 0.388 0
## 10 2012 1 Sun 10 27 White Male 0.204 Moving Vi… 0.436 0
## # ℹ 28,982 more rows
## # A tibble: 28,992 × 11
## year month weekday hour minute race gender age stop_type time
## <dbl> <dbl> <ord> <int> <int> <chr> <chr> <dbl> <chr> <dbl>
## 1 2012 1 Wed 14 43 White Female -0.878 Moving Violation 0.0826
## 2 2012 1 Sun 0 18 White Female 2.43 Equipment -1.98
## 3 2012 1 Sun 0 18 White Male -0.746 Susp DUI -1.98
## 4 2012 1 Sun 8 50 White Female -0.878 Equipment -0.759
## 5 2012 1 Sun 8 56 White Female -1.28 Other -0.745
## 6 2012 1 Sun 9 4 White Male 0.711 Equipment -0.726
## 7 2012 1 Wed 14 50 White Female -0.481 Equipment 0.0993
## 8 2012 1 Wed 15 13 White Male -0.547 Moving Violation 0.154
## 9 2012 1 Sun 9 19 White Female -0.150 Equipment -0.690
## 10 2012 1 Sun 10 27 White Male -0.878 Moving Violation -0.528
## # ℹ 28,982 more rows
## # ℹ 1 more variable: outcome <fct>
## # A tibble: 100 × 3
## k norm_acc stan_acc
## <int> <dbl> <dbl>
## 1 1 -1 -1
## 2 2 -1 -1
## 3 3 -1 -1
## 4 4 -1 -1
## 5 5 -1 -1
## 6 6 -1 -1
## 7 7 -1 -1
## 8 8 -1 -1
## 9 9 -1 -1
## 10 10 -1 -1
## # ℹ 90 more rows
## # A tibble: 100 × 3
## k norm_acc stan_acc
## <int> <dbl> <dbl>
## 1 1 0.647 0.646
## 2 2 0.660 0.658
## 3 3 0.693 0.693
## 4 4 0.704 0.700
## 5 5 0.715 0.712
## 6 6 0.722 0.717
## 7 7 0.730 0.726
## 8 8 0.734 0.731
## 9 9 0.739 0.735
## 10 10 0.739 0.738
## # ℹ 90 more rows
## Confusion Matrix and Statistics
##
## Reference
## Prediction 0 1
## 0 21126 6577
## 1 861 428
##
## Accuracy : 0.743
## 95% CI : (0.738, 0.748)
## No Information Rate : 0.758
## P-Value [Acc > NIR] : 1
##
## Kappa : 0.03
##
## Mcnemar's Test P-Value : <2e-16
##
## Sensitivity : 0.9608
## Specificity : 0.0611
## Pos Pred Value : 0.7626
## Neg Pred Value : 0.3320
## Prevalence : 0.7584
## Detection Rate : 0.7287
## Detection Prevalence : 0.9555
## Balanced Accuracy : 0.5110
##
## 'Positive' Class : 0
##
## Length Class Mode
## positive 1 -none- character
## table 4 table numeric
## overall 7 -none- numeric
## byClass 11 -none- numeric
## mode 1 -none- character
## dots 0 -none- list