This is my coursework. This project is to discover the crime in Boston area. We use the dataset from Kaggle, Crime in Boston
This is a dataset containing records from the new crime incident report system in Boston area, which includes a reduced set of fields focused on capturing the type of incident as well as when and where it occurred.
Crime incident reports are provided by Boston Police Department (BPD) to document the initial details surrounding an incident to which BPD officers respond.
June 14, 2015 to September 3, 2018
I also create an interactive dashboard by tableau. Feel free to check the link and click them.
The link: Crime in Boston Dashboard
library(tidyverse)
## -- Attaching packages ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.3
## v tibble 2.1.3 v dplyr 0.8.5
## v tidyr 1.0.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(DataExplorer)
Boston_Crime <- read.table("Boston_Crime.csv", header = TRUE, sep=",")
Use head() function to view the first few rows.
head(Boston_Crime,5)
## INCIDENT_NUMBER OFFENSE_CODE OFFENSE_CODE_GROUP
## 1 I182080058 2403 Disorderly Conduct
## 2 I182080053 3201 Property Lost
## 3 I182080052 2647 Other
## 4 I182080051 413 Aggravated Assault
## 5 I182080050 3122 Aircraft
## OFFENSE_DESCRIPTION DISTRICT REPORTING_AREA SHOOTING
## 1 DISTURBING THE PEACE E18 495
## 2 PROPERTY - LOST D14 795
## 3 THREATS TO DO BODILY HARM B2 329
## 4 ASSAULT - AGGRAVATED - BATTERY A1 92
## 5 AIRCRAFT INCIDENTS A7 36
## OCCURRED_ON_DATE YEAR MONTH DAY_OF_WEEK HOUR UCR_PART STREET
## 1 2018-10-03 20:13 2018 10 Wednesday 20 Part Two ARLINGTON ST
## 2 2018-08-30 20:00 2018 8 Thursday 20 Part Three ALLSTON ST
## 3 2018-10-03 19:20 2018 10 Wednesday 19 Part Two DEVON ST
## 4 2018-10-03 20:00 2018 10 Wednesday 20 Part One CAMBRIDGE ST
## 5 2018-10-03 20:49 2018 10 Wednesday 20 Part Three PRESCOTT ST
## Lat Long Location
## 1 42.26261 -71.12119 (42.26260773, -71.12118637)
## 2 42.35211 -71.13531 (42.35211146, -71.13531147)
## 3 42.30813 -71.07693 (42.30812619, -71.07692974)
## 4 42.35945 -71.05965 (42.35945371, -71.05964817)
## 5 42.37526 -71.02466 (42.37525782, -71.02466343)
Use str() function to check the structure of the data
str(Boston_Crime)
## 'data.frame': 151764 obs. of 17 variables:
## $ INCIDENT_NUMBER : Factor w/ 134389 levels "142052550","I010370257-00",..: 134389 134388 134387 134386 134385 134384 134383 134382 134381 134380 ...
## $ OFFENSE_CODE : int 2403 3201 2647 413 3122 1402 3803 3301 802 3410 ...
## $ OFFENSE_CODE_GROUP : Factor w/ 66 levels "Aggravated Assault",..: 14 52 46 1 2 63 43 64 61 62 ...
## $ OFFENSE_DESCRIPTION: Factor w/ 242 levels "A&B HANDS, FEET, ETC. - MED. ATTENTION REQ.",..: 62 185 220 13 5 229 160 230 21 221 ...
## $ DISTRICT : Factor w/ 13 levels "","A1","A15",..: 12 9 5 2 4 7 1 5 12 10 ...
## $ REPORTING_AREA : int 495 795 329 92 36 351 NA 603 543 621 ...
## $ SHOOTING : Factor w/ 2 levels "","Y": 1 1 1 1 1 1 1 1 1 1 ...
## $ OCCURRED_ON_DATE : Factor w/ 114576 levels "2015-06-15 0:00",..: 114572 112099 114564 114571 114574 114524 114573 114567 114565 114571 ...
## $ YEAR : int 2018 2018 2018 2018 2018 2018 2018 2018 2018 2018 ...
## $ MONTH : int 10 8 10 10 10 10 10 10 10 10 ...
## $ DAY_OF_WEEK : Factor w/ 7 levels "Friday","Monday",..: 7 5 7 7 7 6 7 7 7 7 ...
## $ HOUR : int 20 20 19 20 20 20 20 19 19 20 ...
## $ UCR_PART : Factor w/ 5 levels "","Other","Part One",..: 5 4 5 3 4 5 4 4 5 4 ...
## $ STREET : Factor w/ 4241 levels ""," ALBANY ST ",..: 180 100 1059 615 3129 1093 1 3834 241 856 ...
## $ Lat : num 42.3 42.4 42.3 42.4 42.4 ...
## $ Long : num -71.1 -71.1 -71.1 -71.1 -71 ...
## $ Location : Factor w/ 15433 levels "(-1.00000000, -1.00000000)",..: 729 12456 5788 13499 14566 4885 7672 9497 477 11790 ...
summary(Boston_Crime)
## INCIDENT_NUMBER OFFENSE_CODE
## I152080623 : 11 Min. : 111
## I172096394 : 10 1st Qu.:1001
## I182065208 : 10 Median :2914
## I162071327 : 9 Mean :2318
## I172056883 : 9 3rd Qu.:3201
## I130041200-00: 8 Max. :3831
## (Other) :151707
## OFFENSE_CODE_GROUP
## Motor Vehicle Accident Response:17733
## Larceny :12268
## Medical Assistance :11193
## Investigate Person : 8883
## Other : 8502
## Drug Violation : 7702
## (Other) :85483
## OFFENSE_DESCRIPTION DISTRICT
## SICK/INJURED/MEDICAL - PERSON : 8908 B2 :23667
## INVESTIGATE PERSON : 8887 C11 :20340
## M/V - LEAVING SCENE - PROPERTY DAMAGE: 7790 D4 :19929
## VANDALISM : 7351 A1 :17074
## ASSAULT SIMPLE - BATTERY : 7076 B3 :16875
## VERBAL DISPUTE : 6190 C6 :11204
## (Other) :105562 (Other):42675
## REPORTING_AREA SHOOTING OCCURRED_ON_DATE YEAR
## Min. : 0.0 :151229 2015-06-18 5:00 : 22 Min. :2015
## 1st Qu.:177.0 Y: 535 2015-07-01 0:00 : 16 1st Qu.:2016
## Median :344.0 2017-06-01 0:00 : 16 Median :2016
## Mean :383.7 2015-12-07 11:38: 14 Mean :2017
## 3rd Qu.:546.0 2015-10-02 21:00: 13 3rd Qu.:2017
## Max. :962.0 2016-04-01 0:00 : 13 Max. :2018
## NA's :9664 (Other) :151670
## MONTH DAY_OF_WEEK HOUR UCR_PART
## Min. : 1.000 Friday :23242 Min. : 0.00 : 42
## 1st Qu.: 4.000 Monday :21896 1st Qu.: 9.00 Other : 578
## Median : 7.000 Saturday :22236 Median :14.00 Part One :29375
## Mean : 6.733 Sunday :19905 Mean :13.08 Part Three:75654
## 3rd Qu.: 9.000 Thursday :21212 3rd Qu.:18.00 Part Two :46115
## Max. :12.000 Tuesday :22050 Max. :23.00
## Wednesday:21223
## STREET Lat Long
## WASHINGTON ST : 6596 Min. :-1.00 Min. :-71.18
## : 5303 1st Qu.:42.30 1st Qu.:-71.10
## BLUE HILL AVE : 3703 Median :42.33 Median :-71.08
## BOYLSTON ST : 3472 Mean :42.21 Mean :-70.89
## DORCHESTER AVE: 2457 3rd Qu.:42.35 3rd Qu.:-71.06
## TREMONT ST : 2288 Max. :42.40 Max. : -1.00
## (Other) :127945 NA's :9460 NA's :9460
## Location
## (0.00000000, 0.00000000) : 9460
## (42.34862382, -71.08277637): 572
## (42.36183857, -71.05976489): 548
## (42.28482577, -71.09137369): 542
## (42.32866284, -71.08563401): 461
## (42.25621592, -71.12401947): 395
## (Other) :139786
Anthor way: to use glimpse() function to see every column in a data frame
glimpse(Boston_Crime)
## Observations: 151,764
## Variables: 17
## $ INCIDENT_NUMBER <fct> I182080058, I182080053, I182080052, I18208...
## $ OFFENSE_CODE <int> 2403, 3201, 2647, 413, 3122, 1402, 3803, 3...
## $ OFFENSE_CODE_GROUP <fct> Disorderly Conduct, Property Lost, Other, ...
## $ OFFENSE_DESCRIPTION <fct> "DISTURBING THE PEACE", "PROPERTY - LOST",...
## $ DISTRICT <fct> E18, D14, B2, A1, A7, C11, , B2, E18, D4, ...
## $ REPORTING_AREA <int> 495, 795, 329, 92, 36, 351, NA, 603, 543, ...
## $ SHOOTING <fct> , , , , , , , , , , , , , , , , , , , , , ...
## $ OCCURRED_ON_DATE <fct> 2018-10-03 20:13, 2018-08-30 20:00, 2018-1...
## $ YEAR <int> 2018, 2018, 2018, 2018, 2018, 2018, 2018, ...
## $ MONTH <int> 10, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10,...
## $ DAY_OF_WEEK <fct> Wednesday, Thursday, Wednesday, Wednesday,...
## $ HOUR <int> 20, 20, 19, 20, 20, 20, 20, 19, 19, 20, 19...
## $ UCR_PART <fct> Part Two, Part Three, Part Two, Part One, ...
## $ STREET <fct> ARLINGTON ST, ALLSTON ST, DEVON ST, CAMBRI...
## $ Lat <dbl> 42.26261, 42.35211, 42.30813, 42.35945, 42...
## $ Long <dbl> -71.12119, -71.13531, -71.07693, -71.05965...
## $ Location <fct> "(42.26260773, -71.12118637)", "(42.352111...
Let’s check the completeness of the data.
plot_intro(Boston_Crime)
plot_correlation(Boston_Crime)
## 6 features with more than 20 categories ignored!
## INCIDENT_NUMBER: 134389 categories
## OFFENSE_CODE_GROUP: 66 categories
## OFFENSE_DESCRIPTION: 242 categories
## OCCURRED_ON_DATE: 114576 categories
## STREET: 4241 categories
## Location: 15433 categories
plot_histogram(Boston_Crime)
plot_bar(Boston_Crime)
## 6 columns ignored with more than 50 categories.
## INCIDENT_NUMBER: 134389 categories
## OFFENSE_CODE_GROUP: 66 categories
## OFFENSE_DESCRIPTION: 242 categories
## OCCURRED_ON_DATE: 114576 categories
## STREET: 4241 categories
## Location: 15433 categories
Boston_Crime %>% separate(OCCURRED_ON_DATE, c("Date", "Time"), sep = " ") %>% mutate(Date = ymd(Date)) %>%
ggplot(aes(Date))+
geom_freqpoly() +
ylab("Number of Crimes")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(30) %>%
ggplot(aes(reorder(OFFENSE_CODE_GROUP,n), n))+
geom_col()+
coord_flip()+
labs(x = NULL, y = 'Counts')
Boston_Crime %>% count(STREET) %>% arrange(-n) %>% head(15) %>%
ggplot(aes(reorder(STREET,n), n))+
geom_col()+
coord_flip()+
labs(x = NULL, y = NULL)
Boston_Crime %>% filter(DISTRICT %in% (Boston_Crime %>% count(DISTRICT) %>% arrange(-n) %>% pull(DISTRICT)),
OFFENSE_CODE_GROUP %in% (Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_CODE_GROUP))
) %>%
ggplot(aes(DISTRICT, fill = OFFENSE_CODE_GROUP))+
geom_bar()+
scale_fill_ordinal()+
coord_flip()
Boston_Crime %>% filter(STREET %in% (Boston_Crime %>% count(STREET) %>% arrange(-n) %>% head(5) %>% pull(STREET)),
OFFENSE_CODE_GROUP %in% (Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_CODE_GROUP))
) %>%
ggplot(aes(STREET, fill = OFFENSE_CODE_GROUP))+
geom_bar(position = "fill")+
scale_fill_ordinal()+
coord_flip()
Boston_Crime %>% filter(STREET %in% (Boston_Crime %>% count(STREET) %>% arrange(-n) %>% head(5) %>% pull(STREET))) %>%
ggplot(aes(DISTRICT, fill = STREET))+
geom_bar(position = "fill")+
coord_flip()+
scale_fill_ordinal()
Boston_Crime %>% filter(STREET %in% (Boston_Crime %>% count(STREET) %>% arrange(-n) %>% head(5) %>% pull(STREET))) %>%
ggplot(aes(DAY_OF_WEEK, fill = STREET))+
geom_bar()+
coord_flip()+
scale_fill_ordinal()
Boston_Crime %>% filter(OFFENSE_CODE_GROUP %in% (Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_CODE_GROUP))) %>%
ggplot(aes(HOUR, fill = OFFENSE_CODE_GROUP))+
geom_bar()+
coord_flip()+
scale_fill_ordinal()
Boston_Crime %>% filter(OFFENSE_CODE_GROUP %in% (Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_CODE_GROUP))) %>%
ggplot(aes(HOUR, fill = OFFENSE_CODE_GROUP))+
geom_bar()+
facet_wrap(~YEAR)+
coord_flip()+
scale_fill_ordinal()
Boston_Crime %>% filter(OFFENSE_CODE_GROUP %in% (Boston_Crime %>% count(OFFENSE_CODE_GROUP) %>% arrange(-n) %>% head(5) %>% pull(OFFENSE_CODE_GROUP))) %>%
ggplot(aes(DISTRICT, fill = OFFENSE_CODE_GROUP))+
geom_bar()+
facet_wrap(~YEAR)+
coord_flip()+
scale_fill_ordinal()
Load libraries
library(e1071)
library(caret)
## Loading required package: lattice
##
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
##
## lift
Import the Data
Choose the columns we needed and filter them our; meanwhile, clean the null value
Boston_Crime_UCR <- Boston_Crime %>% filter(UCR_PART !='') %>% select(UCR_PART, OFFENSE_CODE_GROUP, DISTRICT, DAY_OF_WEEK, HOUR)
Check and study the dataset
summary(Boston_Crime_UCR)
## UCR_PART OFFENSE_CODE_GROUP
## : 0 Motor Vehicle Accident Response:17733
## Other : 578 Larceny :12268
## Part One :29375 Medical Assistance :11193
## Part Three:75654 Investigate Person : 8883
## Part Two :46115 Other : 8502
## Drug Violation : 7702
## (Other) :85441
## DISTRICT DAY_OF_WEEK HOUR
## B2 :23659 Friday :23236 Min. : 0.00
## C11 :20334 Monday :21887 1st Qu.: 9.00
## D4 :19926 Saturday :22232 Median :14.00
## A1 :17072 Sunday :19897 Mean :13.08
## B3 :16867 Thursday :21207 3rd Qu.:18.00
## C6 :11202 Tuesday :22046 Max. :23.00
## (Other):42662 Wednesday:21217
str(Boston_Crime_UCR)
## 'data.frame': 151722 obs. of 5 variables:
## $ UCR_PART : Factor w/ 5 levels "","Other","Part One",..: 5 4 5 3 4 5 4 4 5 4 ...
## $ OFFENSE_CODE_GROUP: Factor w/ 66 levels "Aggravated Assault",..: 14 52 46 1 2 63 43 64 61 62 ...
## $ DISTRICT : Factor w/ 13 levels "","A1","A15",..: 12 9 5 2 4 7 1 5 12 10 ...
## $ DAY_OF_WEEK : Factor w/ 7 levels "Friday","Monday",..: 7 5 7 7 7 6 7 7 7 7 ...
## $ HOUR : int 20 20 19 20 20 20 20 19 19 20 ...
Quick Exploratory Data Analysis
Boston_Crime_UCR %>% filter(UCR_PART %in% (Boston_Crime_UCR %>% count(UCR_PART) %>% arrange(-n) %>% head(5) %>% pull(UCR_PART))) %>%
ggplot(aes(HOUR, fill = UCR_PART))+
geom_bar()+
coord_flip()+
scale_fill_ordinal()
Boston_Crime_UCR %>%
ggplot(aes(x=UCR_PART, y=HOUR, fill=UCR_PART))+
geom_boxplot() +
ggtitle('Box Plot')
Boston_Crime_UCR %>%
ggplot(aes(x=HOUR, fill=UCR_PART))+
geom_density(alpha = 0.8, color = 'black') +
coord_flip()+
ggtitle('Density Plot')
Partition the dataset in the train set and the test set
set.seed(1234)
id <- sample(2, nrow(Boston_Crime_UCR), replace = T, prob = c(0.8, 0.2))
train <- Boston_Crime_UCR[id == 1,]
test <- Boston_Crime_UCR[id == 2,]
Create Naive Bayes model by using the training data set
crime_nb1 <- naiveBayes(as.factor(HOUR)~., data=train, )
crime_nb1
##
## Naive Bayes Classifier for Discrete Predictors
##
## Call:
## naiveBayes.default(x = X, y = Y, laplace = laplace)
##
## A-priori probabilities:
## Y
## 0 1 2 3 4 5
## 0.04822577 0.03008044 0.02420748 0.01427114 0.01049567 0.01076710
## 6 7 8 9 10 11
## 0.01509369 0.02760459 0.04034580 0.04667939 0.05239607 0.05247010
## 12 13 14 15 16 17
## 0.05902578 0.05275799 0.05310346 0.05066873 0.06107391 0.06396104
## 18 19 20 21 22 23
## 0.06386234 0.05537368 0.04855479 0.04454077 0.04040338 0.03403688
##
## Conditional probabilities:
## UCR_PART
## Y Other Part One Part Three Part Two
## 0 0.000000000 0.004434590 0.187105577 0.457274433 0.351185400
## 1 0.000000000 0.004648619 0.185124419 0.458299152 0.351927810
## 2 0.000000000 0.004077472 0.183486239 0.476044852 0.336391437
## 3 0.000000000 0.003458213 0.207492795 0.511239193 0.277809798
## 4 0.000000000 0.003918495 0.224137931 0.518025078 0.253918495
## 5 0.000000000 0.002291826 0.203208556 0.572192513 0.222307105
## 6 0.000000000 0.003814714 0.196185286 0.586376022 0.213623978
## 7 0.000000000 0.003575685 0.170143027 0.611740167 0.214541120
## 8 0.000000000 0.005300714 0.168807339 0.571661570 0.254230377
## 9 0.000000000 0.005991189 0.159471366 0.555418502 0.279118943
## 10 0.000000000 0.005651491 0.169387755 0.532496075 0.292464678
## 11 0.000000000 0.005329989 0.174321994 0.522182160 0.298165857
## 12 0.000000000 0.003483835 0.187151616 0.484253066 0.325111483
## 13 0.000000000 0.003741815 0.185687558 0.504521360 0.306049267
## 14 0.000000000 0.003717472 0.203531599 0.490706320 0.302044610
## 15 0.000000000 0.003084416 0.201623377 0.488474026 0.306818182
## 16 0.000000000 0.002693603 0.198383838 0.478114478 0.320808081
## 17 0.000000000 0.002443416 0.192644033 0.460519547 0.344393004
## 18 0.000000000 0.003219990 0.198093766 0.451571355 0.347114889
## 19 0.000000000 0.002673797 0.203802733 0.460190137 0.333333333
## 20 0.000000000 0.003049297 0.219718787 0.473657462 0.303574454
## 21 0.000000000 0.003878116 0.214219760 0.507848569 0.274053555
## 22 0.000000000 0.003257329 0.218851792 0.511604235 0.266286645
## 23 0.000000000 0.004108265 0.216288062 0.521991300 0.257612373
##
## OFFENSE_CODE_GROUP
## Y Aggravated Assault Aircraft Arson
## 0 0.0301893229 0.0000000000 0.0003411223
## 1 0.0418375718 0.0000000000 0.0002734482
## 2 0.0496092423 0.0000000000 0.0006795787
## 3 0.0351585014 0.0000000000 0.0000000000
## 4 0.0384012539 0.0000000000 0.0007836991
## 5 0.0213903743 0.0007639419 0.0007639419
## 6 0.0152588556 0.0000000000 0.0005449591
## 7 0.0140047676 0.0000000000 0.0002979738
## 8 0.0156982671 0.0002038736 0.0002038736
## 9 0.0119823789 0.0000000000 0.0003524229
## 10 0.0152276295 0.0001569859 0.0000000000
## 11 0.0169305534 0.0003135288 0.0000000000
## 12 0.0165830546 0.0000000000 0.0002787068
## 13 0.0208917992 0.0001559089 0.0000000000
## 14 0.0192069393 0.0001548947 0.0003097893
## 15 0.0215909091 0.0001623377 0.0001623377
## 16 0.0268013468 0.0000000000 0.0002693603
## 17 0.0198045267 0.0001286008 0.0002572016
## 18 0.0202215353 0.0001287996 0.0002575992
## 19 0.0251039810 0.0004456328 0.0004456328
## 20 0.0293071320 0.0001694054 0.0005082162
## 21 0.0323176362 0.0000000000 0.0001846722
## 22 0.0348127036 0.0000000000 0.0000000000
## 23 0.0413243113 0.0002416626 0.0002416626
## OFFENSE_CODE_GROUP
## Y Assembly or Gathering Violations Auto Theft Auto Theft Recovery
## 0 0.0121098414 0.0144976974 0.0039229064
## 1 0.0103910309 0.0131255127 0.0038282745
## 2 0.0050968400 0.0125722052 0.0033978933
## 3 0.0046109510 0.0161383285 0.0028818444
## 4 0.0031347962 0.0242946708 0.0023510972
## 5 0.0000000000 0.0175706646 0.0015278839
## 6 0.0005449591 0.0212534060 0.0032697548
## 7 0.0026817640 0.0116209774 0.0029797378
## 8 0.0014271152 0.0120285423 0.0038735984
## 9 0.0015859031 0.0126872247 0.0049339207
## 10 0.0021978022 0.0122448980 0.0053375196
## 11 0.0017244082 0.0112870356 0.0050164603
## 12 0.0033444816 0.0115663322 0.0029264214
## 13 0.0009354537 0.0121608980 0.0034299969
## 14 0.0015489467 0.0147149938 0.0034076828
## 15 0.0017857143 0.0116883117 0.0027597403
## 16 0.0016161616 0.0117171717 0.0020202020
## 17 0.0010288066 0.0122170782 0.0020576132
## 18 0.0011591963 0.0142967543 0.0027047913
## 19 0.0011883541 0.0164884135 0.0019310755
## 20 0.0010164323 0.0225309165 0.0023716754
## 21 0.0016620499 0.0236380425 0.0035087719
## 22 0.0030537459 0.0250407166 0.0032573290
## 23 0.0125664572 0.0212663122 0.0033832769
## OFFENSE_CODE_GROUP
## Y Ballistics Bomb Hoax Burglary - No Property Taken
## 0 0.0027289783 0.0003411223 0.0000000000
## 1 0.0054689636 0.0000000000 0.0000000000
## 2 0.0071355759 0.0000000000 0.0000000000
## 3 0.0109510086 0.0000000000 0.0000000000
## 4 0.0070532915 0.0000000000 0.0000000000
## 5 0.0045836516 0.0000000000 0.0000000000
## 6 0.0038147139 0.0000000000 0.0000000000
## 7 0.0011918951 0.0005959476 0.0000000000
## 8 0.0016309888 0.0000000000 0.0000000000
## 9 0.0015859031 0.0000000000 0.0000000000
## 10 0.0032967033 0.0006279435 0.0000000000
## 11 0.0015676438 0.0001567644 0.0001567644
## 12 0.0029264214 0.0005574136 0.0000000000
## 13 0.0021827253 0.0003118179 0.0000000000
## 14 0.0020136307 0.0000000000 0.0000000000
## 15 0.0017857143 0.0003246753 0.0000000000
## 16 0.0020202020 0.0002693603 0.0000000000
## 17 0.0020576132 0.0002572016 0.0000000000
## 18 0.0023183926 0.0002575992 0.0000000000
## 19 0.0028223411 0.0001485443 0.0000000000
## 20 0.0015246485 0.0000000000 0.0000000000
## 21 0.0025854109 0.0001846722 0.0000000000
## 22 0.0048859935 0.0000000000 0.0000000000
## 23 0.0070082165 0.0002416626 0.0000000000
## OFFENSE_CODE_GROUP
## Y Commercial Burglary Confidence Games Counterfeiting
## 0 0.0056285178 0.0274603445 0.0080163739
## 1 0.0068362045 0.0051955154 0.0013672409
## 2 0.0067957866 0.0057764186 0.0003397893
## 3 0.0195965418 0.0034582133 0.0023054755
## 4 0.0297805643 0.0000000000 0.0031347962
## 5 0.0183346066 0.0038197097 0.0007639419
## 6 0.0147138965 0.0076294278 0.0021798365
## 7 0.0071513707 0.0077473182 0.0020858164
## 8 0.0053007136 0.0099898063 0.0040774720
## 9 0.0054625551 0.0149779736 0.0065198238
## 10 0.0025117739 0.0095761381 0.0048665620
## 11 0.0018811726 0.0083085123 0.0064273397
## 12 0.0023690078 0.0154682274 0.0072463768
## 13 0.0009354537 0.0124727159 0.0067040848
## 14 0.0023234201 0.0117719950 0.0063506815
## 15 0.0019480519 0.0125000000 0.0060064935
## 16 0.0018855219 0.0082154882 0.0045791246
## 17 0.0012860082 0.0086162551 0.0047582305
## 18 0.0025759918 0.0099175683 0.0028335909
## 19 0.0031194296 0.0077243018 0.0026737968
## 20 0.0022022700 0.0050821616 0.0028798916
## 21 0.0022160665 0.0053554940 0.0029547553
## 22 0.0030537459 0.0065146580 0.0012214984
## 23 0.0053165781 0.0041082649 0.0009666506
## OFFENSE_CODE_GROUP
## Y Criminal Harassment Disorderly Conduct Drug Violation Embezzlement
## 0 0.0005116834 0.0126215248 0.0320654955 0.0017056115
## 1 0.0002734482 0.0169537873 0.0273448182 0.0002734482
## 2 0.0000000000 0.0220863065 0.0227658852 0.0000000000
## 3 0.0005763689 0.0178674352 0.0161383285 0.0000000000
## 4 0.0000000000 0.0078369906 0.0274294671 0.0007836991
## 5 0.0007639419 0.0061115355 0.0160427807 0.0000000000
## 6 0.0005449591 0.0070844687 0.0207084469 0.0000000000
## 7 0.0002979738 0.0047675805 0.0172824791 0.0000000000
## 8 0.0000000000 0.0069317023 0.0185524975 0.0010193680
## 9 0.0003524229 0.0066960352 0.0232599119 0.0015859031
## 10 0.0006279435 0.0065934066 0.0365777080 0.0010989011
## 11 0.0004702931 0.0062705753 0.0429534410 0.0004702931
## 12 0.0005574136 0.0072463768 0.0436176143 0.0016722408
## 13 0.0004677268 0.0067040848 0.0559713128 0.0007795447
## 14 0.0004646840 0.0044919455 0.0565365551 0.0015489467
## 15 0.0003246753 0.0042207792 0.0639610390 0.0009740260
## 16 0.0005387205 0.0057912458 0.0857912458 0.0005387205
## 17 0.0001286008 0.0069444444 0.1028806584 0.0005144033
## 18 0.0003863988 0.0061823802 0.0994332818 0.0005151984
## 19 0.0005941771 0.0068330362 0.0861556744 0.0007427213
## 20 0.0005082162 0.0096561071 0.0592918855 0.0005082162
## 21 0.0000000000 0.0072022161 0.0326869806 0.0003693444
## 22 0.0002035831 0.0107899023 0.0219869707 0.0002035831
## 23 0.0000000000 0.0089415176 0.0154664089 0.0007249879
## OFFENSE_CODE_GROUP
## Y Evading Fare Explosives Fire Related Reports Firearm Discovery
## 0 0.0020467338 0.0001705611 0.0051168344 0.0015350503
## 1 0.0038282745 0.0002734482 0.0084768936 0.0013672409
## 2 0.0047570506 0.0000000000 0.0074753653 0.0010193680
## 3 0.0028818444 0.0000000000 0.0109510086 0.0017291066
## 4 0.0031347962 0.0000000000 0.0109717868 0.0023510972
## 5 0.0007639419 0.0000000000 0.0084033613 0.0022918258
## 6 0.0005449591 0.0000000000 0.0038147139 0.0005449591
## 7 0.0008939213 0.0000000000 0.0053635280 0.0008939213
## 8 0.0006116208 0.0000000000 0.0032619776 0.0030581040
## 9 0.0003524229 0.0001762115 0.0054625551 0.0028193833
## 10 0.0007849294 0.0001569859 0.0056514914 0.0021978022
## 11 0.0006270575 0.0000000000 0.0040758740 0.0031352877
## 12 0.0004180602 0.0000000000 0.0058528428 0.0033444816
## 13 0.0012472716 0.0003118179 0.0045213595 0.0035859058
## 14 0.0006195787 0.0000000000 0.0068153656 0.0038723668
## 15 0.0008116883 0.0000000000 0.0060064935 0.0016233766
## 16 0.0008080808 0.0000000000 0.0076767677 0.0029629630
## 17 0.0010288066 0.0000000000 0.0050154321 0.0018004115
## 18 0.0007727975 0.0000000000 0.0068263782 0.0016743946
## 19 0.0019310755 0.0000000000 0.0063874034 0.0020796197
## 20 0.0008470269 0.0000000000 0.0084702694 0.0018634593
## 21 0.0020313943 0.0000000000 0.0075715605 0.0018467221
## 22 0.0016286645 0.0000000000 0.0061074919 0.0002035831
## 23 0.0026582890 0.0002416626 0.0060415660 0.0007249879
## OFFENSE_CODE_GROUP
## Y Firearm Violations Fraud Gambling Harassment
## 0 0.0071635681 0.0409346751 0.0000000000 0.0165444312
## 1 0.0084768936 0.0046486191 0.0000000000 0.0060158600
## 2 0.0084947333 0.0047570506 0.0000000000 0.0037376826
## 3 0.0074927954 0.0028818444 0.0000000000 0.0069164265
## 4 0.0086206897 0.0039184953 0.0000000000 0.0047021944
## 5 0.0061115355 0.0061115355 0.0007639419 0.0068754775
## 6 0.0010899183 0.0070844687 0.0000000000 0.0049046322
## 7 0.0017878427 0.0080452920 0.0000000000 0.0125148987
## 8 0.0024464832 0.0156982671 0.0000000000 0.0101936799
## 9 0.0031718062 0.0262555066 0.0000000000 0.0142731278
## 10 0.0037676609 0.0270015699 0.0000000000 0.0164835165
## 11 0.0048596959 0.0246120082 0.0000000000 0.0125411507
## 12 0.0052954292 0.0377647715 0.0000000000 0.0174191750
## 13 0.0067040848 0.0210477081 0.0001559089 0.0151231681
## 14 0.0044919455 0.0255576208 0.0000000000 0.0140954151
## 15 0.0047077922 0.0202922078 0.0000000000 0.0146103896
## 16 0.0049831650 0.0183164983 0.0000000000 0.0123905724
## 17 0.0061728395 0.0169753086 0.0001286008 0.0132458848
## 18 0.0065687790 0.0135239567 0.0000000000 0.0124935600
## 19 0.0077243018 0.0136660725 0.0000000000 0.0115864528
## 20 0.0055903778 0.0111807555 0.0000000000 0.0155852956
## 21 0.0053554940 0.0094182825 0.0001846722 0.0101569714
## 22 0.0052931596 0.0032573290 0.0000000000 0.0091612378
## 23 0.0053165781 0.0038666022 0.0000000000 0.0070082165
## OFFENSE_CODE_GROUP
## Y Harbor Related Incidents HOME INVASION Homicide HUMAN TRAFFICKING
## 0 0.0003411223 0.0000000000 0.0006822446 0.0000000000
## 1 0.0005468964 0.0000000000 0.0010937927 0.0000000000
## 2 0.0006795787 0.0000000000 0.0006795787 0.0000000000
## 3 0.0000000000 0.0000000000 0.0011527378 0.0000000000
## 4 0.0015673981 0.0000000000 0.0007836991 0.0000000000
## 5 0.0000000000 0.0000000000 0.0000000000 0.0000000000
## 6 0.0005449591 0.0000000000 0.0010899183 0.0000000000
## 7 0.0002979738 0.0000000000 0.0002979738 0.0000000000
## 8 0.0002038736 0.0000000000 0.0002038736 0.0000000000
## 9 0.0003524229 0.0000000000 0.0000000000 0.0000000000
## 10 0.0004709576 0.0000000000 0.0003139717 0.0000000000
## 11 0.0007838219 0.0000000000 0.0001567644 0.0000000000
## 12 0.0005574136 0.0000000000 0.0000000000 0.0000000000
## 13 0.0007795447 0.0000000000 0.0001559089 0.0000000000
## 14 0.0000000000 0.0000000000 0.0001548947 0.0000000000
## 15 0.0003246753 0.0000000000 0.0001623377 0.0000000000
## 16 0.0010774411 0.0000000000 0.0002693603 0.0000000000
## 17 0.0009002058 0.0000000000 0.0005144033 0.0000000000
## 18 0.0007727975 0.0000000000 0.0003863988 0.0000000000
## 19 0.0014854427 0.0000000000 0.0004456328 0.0000000000
## 20 0.0003388108 0.0000000000 0.0008470269 0.0000000000
## 21 0.0005540166 0.0000000000 0.0007386888 0.0000000000
## 22 0.0002035831 0.0000000000 0.0010179153 0.0000000000
## 23 0.0004833253 0.0000000000 0.0019333011 0.0000000000
## OFFENSE_CODE_GROUP
## Y HUMAN TRAFFICKING - INVOLUNTARY SERVITUDE Investigate Person
## 0 0.0000000000 0.0499744158
## 1 0.0000000000 0.0451189500
## 2 0.0000000000 0.0489296636
## 3 0.0000000000 0.0593659942
## 4 0.0000000000 0.0611285266
## 5 0.0000000000 0.0519480519
## 6 0.0000000000 0.0446866485
## 7 0.0000000000 0.0482717521
## 8 0.0000000000 0.0470948012
## 9 0.0000000000 0.0579735683
## 10 0.0000000000 0.0588697017
## 11 0.0000000000 0.0638031039
## 12 0.0000000000 0.0617335563
## 13 0.0000000000 0.0671967571
## 14 0.0000000000 0.0628872367
## 15 0.0000000000 0.0665584416
## 16 0.0000000000 0.0615488215
## 17 0.0000000000 0.0565843621
## 18 0.0000000000 0.0622102009
## 19 0.0000000000 0.0655080214
## 20 0.0000000000 0.0598001016
## 21 0.0000000000 0.0633425669
## 22 0.0000000000 0.0629071661
## 23 0.0000000000 0.0563073949
## OFFENSE_CODE_GROUP
## Y INVESTIGATE PERSON Investigate Property Landlord/Tenant Disputes
## 0 0.0000000000 0.0411052362 0.0027289783
## 1 0.0000000000 0.0388296418 0.0008203445
## 2 0.0000000000 0.0530071356 0.0006795787
## 3 0.0000000000 0.0680115274 0.0005763689
## 4 0.0000000000 0.0611285266 0.0000000000
## 5 0.0000000000 0.0481283422 0.0015278839
## 6 0.0000000000 0.0441416894 0.0010899183
## 7 0.0000000000 0.0390345650 0.0023837902
## 8 0.0000000000 0.0250764526 0.0024464832
## 9 0.0000000000 0.0320704846 0.0033480176
## 10 0.0000000000 0.0324960754 0.0047095761
## 11 0.0000000000 0.0308825835 0.0048596959
## 12 0.0000000000 0.0333054627 0.0043199554
## 13 0.0000000000 0.0293108824 0.0037418148
## 14 0.0000000000 0.0294299876 0.0030978934
## 15 0.0000000000 0.0336038961 0.0025974026
## 16 0.0000000000 0.0432323232 0.0026936027
## 17 0.0000000000 0.0324074074 0.0033436214
## 18 0.0000000000 0.0280783101 0.0030911901
## 19 0.0000000000 0.0271836007 0.0037136067
## 20 0.0000000000 0.0315094020 0.0042351347
## 21 0.0000000000 0.0360110803 0.0029547553
## 22 0.0000000000 0.0337947883 0.0018322476
## 23 0.0000000000 0.0478492025 0.0031416143
## OFFENSE_CODE_GROUP
## Y Larceny Larceny From Motor Vehicle
## 0 0.0617431349 0.0392290636
## 1 0.0462127427 0.0330872300
## 2 0.0441726130 0.0258239891
## 3 0.0409221902 0.0368876081
## 4 0.0407523511 0.0352664577
## 5 0.0404889228 0.0504201681
## 6 0.0485013624 0.0441416894
## 7 0.0536352801 0.0455899881
## 8 0.0662589195 0.0373088685
## 9 0.0669603524 0.0352422907
## 10 0.0857142857 0.0287284144
## 11 0.0940586299 0.0230443643
## 12 0.1040969900 0.0252229654
## 13 0.1049267228 0.0219831618
## 14 0.1096654275 0.0252478315
## 15 0.1084415584 0.0267857143
## 16 0.0996632997 0.0292255892
## 17 0.0949074074 0.0340792181
## 18 0.0909325090 0.0383822772
## 19 0.0846702317 0.0405525847
## 20 0.0828392343 0.0406572929
## 21 0.0664819945 0.0474607572
## 22 0.0549674267 0.0531351792
## 23 0.0480908652 0.0502658289
## OFFENSE_CODE_GROUP
## Y License Plate Related Incidents License Violation Liquor Violation
## 0 0.0028995395 0.0252430496 0.0049462732
## 1 0.0008203445 0.0216024063 0.0030079300
## 2 0.0010193680 0.0129119946 0.0013591573
## 3 0.0000000000 0.0040345821 0.0017291066
## 4 0.0000000000 0.0015673981 0.0007836991
## 5 0.0015278839 0.0000000000 0.0000000000
## 6 0.0010899183 0.0000000000 0.0005449591
## 7 0.0008939213 0.0002979738 0.0002979738
## 8 0.0040774720 0.0000000000 0.0002038736
## 9 0.0022907489 0.0005286344 0.0021145374
## 10 0.0009419152 0.0007849294 0.0039246468
## 11 0.0012541151 0.0036055808 0.0070543972
## 12 0.0022296544 0.0029264214 0.0073857302
## 13 0.0015590895 0.0042095416 0.0026504521
## 14 0.0015489467 0.0018587361 0.0015489467
## 15 0.0008116883 0.0011363636 0.0009740260
## 16 0.0014814815 0.0012121212 0.0030976431
## 17 0.0015432099 0.0037294239 0.0057870370
## 18 0.0018031942 0.0018031942 0.0045079856
## 19 0.0014854427 0.0013368984 0.0038621509
## 20 0.0025410808 0.0028798916 0.0027104862
## 21 0.0020313943 0.0055401662 0.0024007387
## 22 0.0016286645 0.0122149837 0.0048859935
## 23 0.0009666506 0.0289995167 0.0053165781
## OFFENSE_CODE_GROUP
## Y Manslaughter Medical Assistance Missing Person Located
## 0 0.0000000000 0.0622548184 0.0167149923
## 1 0.0002734482 0.0776592836 0.0131255127
## 2 0.0000000000 0.0750934421 0.0118926266
## 3 0.0005763689 0.0870317003 0.0109510086
## 4 0.0007836991 0.1042319749 0.0101880878
## 5 0.0000000000 0.1077158136 0.0168067227
## 6 0.0000000000 0.0801089918 0.0261580381
## 7 0.0000000000 0.0682359952 0.0208581645
## 8 0.0002038736 0.0678899083 0.0189602446
## 9 0.0000000000 0.0703083700 0.0130396476
## 10 0.0000000000 0.0839874411 0.0139717425
## 11 0.0000000000 0.0736792601 0.0128546794
## 12 0.0000000000 0.0714882943 0.0139353400
## 13 0.0000000000 0.0834112878 0.0152790770
## 14 0.0000000000 0.0755885998 0.0154894672
## 15 0.0000000000 0.0711038961 0.0125000000
## 16 0.0001346801 0.0649158249 0.0146801347
## 17 0.0000000000 0.0653292181 0.0128600823
## 18 0.0000000000 0.0575734158 0.0140391551
## 19 0.0000000000 0.0701128936 0.0148544266
## 20 0.0001694054 0.0738607488 0.0198204303
## 21 0.0000000000 0.0877192982 0.0193905817
## 22 0.0000000000 0.0804153094 0.0270765472
## 23 0.0000000000 0.0775737071 0.0193330111
## OFFENSE_CODE_GROUP
## Y Missing Person Reported Motor Vehicle Accident Response
## 0 0.0129626471 0.0776053215
## 1 0.0109379273 0.0976210008
## 2 0.0115528372 0.1281005776
## 3 0.0080691643 0.1279538905
## 4 0.0054858934 0.1285266458
## 5 0.0122230710 0.1611917494
## 6 0.0234332425 0.1820163488
## 7 0.0172824791 0.1576281287
## 8 0.0132517839 0.1445463812
## 9 0.0096916300 0.1207048458
## 10 0.0108320251 0.1006279435
## 11 0.0116005644 0.1094215394
## 12 0.0117056856 0.1020066890
## 13 0.0123168070 0.1114748987
## 14 0.0148698885 0.1140024783
## 15 0.0108766234 0.1310064935
## 16 0.0111784512 0.1239057239
## 17 0.0101594650 0.1225565844
## 18 0.0103039670 0.1150180319
## 19 0.0092097445 0.1088829471
## 20 0.0120277825 0.1080806370
## 21 0.0156971376 0.1165281625
## 22 0.0207654723 0.1209283388
## 23 0.0132914451 0.1227646206
## OFFENSE_CODE_GROUP
## Y Offenses Against Child / Family Operating Under the Influence
## 0 0.0010233669 0.0032406618
## 1 0.0013672409 0.0090237900
## 2 0.0000000000 0.0088345226
## 3 0.0005763689 0.0040345821
## 4 0.0007836991 0.0039184953
## 5 0.0000000000 0.0022918258
## 6 0.0005449591 0.0000000000
## 7 0.0026817640 0.0002979738
## 8 0.0014271152 0.0002038736
## 9 0.0019383260 0.0001762115
## 10 0.0015698587 0.0004709576
## 11 0.0018811726 0.0007838219
## 12 0.0022296544 0.0006967670
## 13 0.0020268163 0.0004677268
## 14 0.0017038414 0.0006195787
## 15 0.0014610390 0.0000000000
## 16 0.0026936027 0.0008080808
## 17 0.0029578189 0.0010288066
## 18 0.0016743946 0.0005151984
## 19 0.0014854427 0.0019310755
## 20 0.0011858377 0.0027104862
## 21 0.0020313943 0.0027700831
## 22 0.0016286645 0.0032573290
## 23 0.0002416626 0.0021749638
## OFFENSE_CODE_GROUP
## Y Other Other Burglary Phone Call Complaints
## 0 0.0521917107 0.0017056115 0.0001705611
## 1 0.0587913590 0.0008203445 0.0002734482
## 2 0.0533469249 0.0010193680 0.0000000000
## 3 0.0489913545 0.0028818444 0.0000000000
## 4 0.0446708464 0.0023510972 0.0000000000
## 5 0.0427807487 0.0030557678 0.0000000000
## 6 0.0376021798 0.0027247956 0.0000000000
## 7 0.0435041716 0.0014898689 0.0000000000
## 8 0.0591233435 0.0020387360 0.0002038736
## 9 0.0629074890 0.0017621145 0.0003524229
## 10 0.0616954474 0.0003139717 0.0003139717
## 11 0.0689763286 0.0020379370 0.0001567644
## 12 0.0661928651 0.0012541806 0.0001393534
## 13 0.0639226692 0.0003118179 0.0001559089
## 14 0.0509603470 0.0015489467 0.0000000000
## 15 0.0590909091 0.0019480519 0.0000000000
## 16 0.0544107744 0.0014814815 0.0001346801
## 17 0.0480967078 0.0018004115 0.0000000000
## 18 0.0582174137 0.0006439979 0.0001287996
## 19 0.0564468212 0.0007427213 0.0000000000
## 20 0.0543791293 0.0020328646 0.0000000000
## 21 0.0500461681 0.0012927054 0.0001846722
## 22 0.0445846906 0.0012214984 0.0000000000
## 23 0.0420492992 0.0016916385 0.0000000000
## OFFENSE_CODE_GROUP
## Y Police Service Incidents Prisoner Related Incidents Property Found
## 0 0.0081869350 0.0006822446 0.0071635681
## 1 0.0084768936 0.0008203445 0.0046486191
## 2 0.0054366293 0.0003397893 0.0074753653
## 3 0.0046109510 0.0005763689 0.0069164265
## 4 0.0047021944 0.0000000000 0.0054858934
## 5 0.0244461421 0.0000000000 0.0091673033
## 6 0.0092643052 0.0005449591 0.0119891008
## 7 0.0083432658 0.0011918951 0.0119189511
## 8 0.0120285423 0.0012232416 0.0165137615
## 9 0.0128634361 0.0012334802 0.0186784141
## 10 0.0172684458 0.0009419152 0.0163265306
## 11 0.0133249726 0.0006270575 0.0128546794
## 12 0.0112876254 0.0005574136 0.0149108138
## 13 0.0082631743 0.0000000000 0.0157468039
## 14 0.0103779430 0.0012391574 0.0147149938
## 15 0.0071428571 0.0012987013 0.0134740260
## 16 0.0083501684 0.0005387205 0.0091582492
## 17 0.0061728395 0.0009002058 0.0101594650
## 18 0.0078567749 0.0006439979 0.0109479650
## 19 0.0059417706 0.0000000000 0.0109922757
## 20 0.0050821616 0.0006776215 0.0105031340
## 21 0.0064635272 0.0003693444 0.0108956602
## 22 0.0052931596 0.0000000000 0.0103827362
## 23 0.0041082649 0.0002416626 0.0074915418
## OFFENSE_CODE_GROUP
## Y Property Lost Property Related Damage Prostitution
## 0 0.0395701859 0.0015350503 0.0010233669
## 1 0.0213289582 0.0016406891 0.0027344818
## 2 0.0231056745 0.0013591573 0.0010193680
## 3 0.0155619597 0.0028818444 0.0005763689
## 4 0.0062695925 0.0023510972 0.0054858934
## 5 0.0076394194 0.0030557678 0.0015278839
## 6 0.0234332425 0.0038147139 0.0000000000
## 7 0.0202622169 0.0041716329 0.0000000000
## 8 0.0246687054 0.0034658512 0.0004077472
## 9 0.0296035242 0.0035242291 0.0001762115
## 10 0.0324960754 0.0029827316 0.0000000000
## 11 0.0384072739 0.0042326383 0.0009405863
## 12 0.0457079153 0.0023690078 0.0005574136
## 13 0.0377299657 0.0040536327 0.0023386342
## 14 0.0393432466 0.0043370508 0.0009293680
## 15 0.0366883117 0.0027597403 0.0012987013
## 16 0.0360942761 0.0026936027 0.0008080808
## 17 0.0304783951 0.0038580247 0.0007716049
## 18 0.0287223081 0.0028335909 0.0005151984
## 19 0.0264408794 0.0040106952 0.0002970885
## 20 0.0291377266 0.0016940539 0.0008470269
## 21 0.0238227147 0.0011080332 0.0000000000
## 22 0.0250407166 0.0014250814 0.0004071661
## 23 0.0280328661 0.0021749638 0.0007249879
## OFFENSE_CODE_GROUP
## Y Recovered Stolen Property Residential Burglary
## 0 0.0037523452 0.0173972369
## 1 0.0084768936 0.0153130982
## 2 0.0040774720 0.0115528372
## 3 0.0063400576 0.0282420749
## 4 0.0054858934 0.0235109718
## 5 0.0045836516 0.0252100840
## 6 0.0043596730 0.0310626703
## 7 0.0032777116 0.0277115614
## 8 0.0040774720 0.0238532110
## 9 0.0051101322 0.0197356828
## 10 0.0045525903 0.0182103611
## 11 0.0043894027 0.0164602602
## 12 0.0041806020 0.0183946488
## 13 0.0040536327 0.0132522607
## 14 0.0049566295 0.0164188352
## 15 0.0032467532 0.0150974026
## 16 0.0044444444 0.0158922559
## 17 0.0041152263 0.0169753086
## 18 0.0054095827 0.0181607419
## 19 0.0046048723 0.0167855021
## 20 0.0050821616 0.0157547010
## 21 0.0038781163 0.0179132041
## 22 0.0052931596 0.0173045603
## 23 0.0036249396 0.0198163364
## OFFENSE_CODE_GROUP
## Y Restraining Order Violations Robbery Search Warrants
## 0 0.0030701006 0.0160327477 0.0028995395
## 1 0.0032813782 0.0267979218 0.0002734482
## 2 0.0016989467 0.0312606184 0.0013591573
## 3 0.0046109510 0.0265129683 0.0005763689
## 4 0.0039184953 0.0289968652 0.0117554859
## 5 0.0030557678 0.0267379679 0.0084033613
## 6 0.0038147139 0.0174386921 0.0065395095
## 7 0.0044696067 0.0086412396 0.0026817640
## 8 0.0053007136 0.0061162080 0.0016309888
## 9 0.0054625551 0.0056387665 0.0037004405
## 10 0.0043956044 0.0061224490 0.0047095761
## 11 0.0058002822 0.0084652767 0.0050164603
## 12 0.0076644370 0.0076644370 0.0033444816
## 13 0.0057686311 0.0110695354 0.0046772685
## 14 0.0061957869 0.0142503098 0.0038723668
## 15 0.0050324675 0.0139610390 0.0029220779
## 16 0.0061952862 0.0114478114 0.0035016835
## 17 0.0050154321 0.0110596708 0.0027006173
## 18 0.0051519835 0.0124935600 0.0018031942
## 19 0.0038621509 0.0158942365 0.0013368984
## 20 0.0055903778 0.0235473488 0.0011858377
## 21 0.0040627886 0.0221606648 0.0016620499
## 22 0.0034609121 0.0282980456 0.0012214984
## 23 0.0041082649 0.0265828903 0.0009666506
## OFFENSE_CODE_GROUP
## Y Service Simple Assault Towed Vandalism Verbal Disputes
## 0 0.0005116834 0.0573085451 0.0266075388 0.0562851782 0.0363295241
## 1 0.0008203445 0.0855892808 0.0262510254 0.0639868745 0.0377358491
## 2 0.0003397893 0.0893645940 0.0220863065 0.0625212368 0.0346585117
## 3 0.0000000000 0.0605187320 0.0305475504 0.0657060519 0.0461095101
## 4 0.0000000000 0.0501567398 0.0313479624 0.0595611285 0.0391849530
## 5 0.0000000000 0.0473644003 0.0466004584 0.0641711230 0.0290297937
## 6 0.0010899183 0.0348773842 0.0588555858 0.0697547684 0.0376021798
## 7 0.0005959476 0.0396305125 0.1495828367 0.0551251490 0.0300953516
## 8 0.0006116208 0.0397553517 0.1092762487 0.0503567788 0.0338430173
## 9 0.0005286344 0.0320704846 0.0881057269 0.0431718062 0.0324229075
## 10 0.0012558870 0.0367346939 0.0635792779 0.0425431711 0.0373626374
## 11 0.0012541151 0.0412290328 0.0473428437 0.0396613889 0.0337043424
## 12 0.0004180602 0.0457079153 0.0257803790 0.0366499443 0.0321906355
## 13 0.0009354537 0.0447458684 0.0249454319 0.0366386031 0.0383536015
## 14 0.0012391574 0.0529739777 0.0165737299 0.0368649318 0.0381040892
## 15 0.0009740260 0.0508116883 0.0128246753 0.0428571429 0.0436688312
## 16 0.0008080808 0.0486195286 0.0162962963 0.0424242424 0.0363636364
## 17 0.0012860082 0.0495113169 0.0176183128 0.0432098765 0.0340792181
## 18 0.0009015971 0.0477846471 0.0153271510 0.0458526533 0.0440494590
## 19 0.0011883541 0.0536244801 0.0172311349 0.0506535948 0.0510992276
## 20 0.0013552431 0.0489581569 0.0176181603 0.0581060478 0.0547179400
## 21 0.0009233610 0.0541089566 0.0238227147 0.0629732225 0.0585410896
## 22 0.0010179153 0.0604641694 0.0223941368 0.0639250814 0.0590390879
## 23 0.0004833253 0.0645239246 0.0161913968 0.0671822136 0.0575157081
## OFFENSE_CODE_GROUP
## Y Violations Warrant Arrests
## 0 0.0179089203 0.0213201433
## 1 0.0363686081 0.0281651627
## 2 0.0343187224 0.0224260958
## 3 0.0149855908 0.0184438040
## 4 0.0172413793 0.0219435737
## 5 0.0084033613 0.0267379679
## 6 0.0076294278 0.0239782016
## 7 0.0086412396 0.0184743743
## 8 0.0242609582 0.0356778797
## 9 0.0276651982 0.0440528634
## 10 0.0274725275 0.0353218210
## 11 0.0238281862 0.0377802163
## 12 0.0170011148 0.0277313266
## 13 0.0176177113 0.0271281572
## 14 0.0176579926 0.0294299876
## 15 0.0128246753 0.0254870130
## 16 0.0150841751 0.0242424242
## 17 0.0217335391 0.0344650206
## 18 0.0251159196 0.0312982998
## 19 0.0161913250 0.0261437908
## 20 0.0121971879 0.0242249704
## 21 0.0151431210 0.0175438596
## 22 0.0152687296 0.0126221498
## 23 0.0130497825 0.0130497825
##
## DISTRICT
## Y A1 A15 A7 B2
## 0 0.009039741 0.129967593 0.018761726 0.035817841 0.144976974
## 1 0.004922067 0.180749248 0.012031720 0.052502051 0.157506153
## 2 0.007815155 0.201495073 0.009174312 0.051987768 0.159021407
## 3 0.006340058 0.141210375 0.021325648 0.044380403 0.180979827
## 4 0.003918495 0.115987461 0.014890282 0.038401254 0.151253918
## 5 0.009167303 0.099312452 0.017570665 0.050420168 0.184873950
## 6 0.002179837 0.087193460 0.027247956 0.045776567 0.148773842
## 7 0.006257449 0.099523242 0.020858164 0.042014303 0.134684148
## 8 0.006320082 0.097043833 0.025688073 0.040163099 0.139449541
## 9 0.003171806 0.105903084 0.023083700 0.043700441 0.140616740
## 10 0.005180534 0.113814757 0.022448980 0.038147567 0.141444270
## 11 0.005800282 0.113967707 0.023044364 0.039504625 0.155353504
## 12 0.004459309 0.111900780 0.022157191 0.040133779 0.157329989
## 13 0.007171812 0.108356720 0.022450889 0.042407234 0.145307141
## 14 0.005731103 0.098358116 0.019206939 0.040737299 0.150402726
## 15 0.006331169 0.110714286 0.019480519 0.040097403 0.156331169
## 16 0.004579125 0.105993266 0.018855219 0.041616162 0.151111111
## 17 0.006430041 0.119341564 0.015432099 0.040380658 0.157664609
## 18 0.007599176 0.108191654 0.019319938 0.040700670 0.161643483
## 19 0.006833036 0.096405229 0.021093286 0.044266191 0.158199643
## 20 0.005759783 0.098424530 0.021853295 0.044214806 0.157885821
## 21 0.004801477 0.084949215 0.022714681 0.038227147 0.169529086
## 22 0.004885993 0.104030945 0.017508143 0.041123779 0.183021173
## 23 0.003866602 0.122281295 0.018124698 0.044465926 0.165780570
## DISTRICT
## Y B3 C11 C6 D14 D4
## 0 0.105747911 0.143100802 0.080334300 0.068736142 0.129285349
## 1 0.105824446 0.122504785 0.068635494 0.069729286 0.114848236
## 2 0.099218485 0.113829426 0.061501869 0.071355759 0.122663948
## 3 0.110086455 0.147550432 0.062824207 0.070317003 0.098559078
## 4 0.130877743 0.170062696 0.077586207 0.066614420 0.115203762
## 5 0.108479756 0.158899924 0.061879297 0.058823529 0.110771581
## 6 0.119891008 0.172207084 0.069209809 0.053405995 0.113896458
## 7 0.112038141 0.120679380 0.077473182 0.087902265 0.138557807
## 8 0.110907238 0.131498471 0.076452599 0.075229358 0.141080530
## 9 0.103964758 0.128634361 0.080000000 0.066079295 0.126696035
## 10 0.110047096 0.130769231 0.075824176 0.059968603 0.145211931
## 11 0.109264775 0.131368553 0.073365731 0.060511052 0.136855306
## 12 0.099637681 0.120958751 0.069537347 0.062709030 0.147296544
## 13 0.116152167 0.122700343 0.075615840 0.058621765 0.142033053
## 14 0.111059480 0.129337051 0.080390335 0.059014870 0.143897150
## 15 0.103896104 0.130357143 0.073863636 0.061688312 0.141233766
## 16 0.108417508 0.138316498 0.080673401 0.058720539 0.131447811
## 17 0.100051440 0.130787037 0.074331276 0.057741770 0.137217078
## 18 0.115018032 0.131633179 0.074446162 0.057315817 0.133436373
## 19 0.121509210 0.136660725 0.076945930 0.060903149 0.127599525
## 20 0.119430798 0.148737930 0.069286803 0.064374047 0.122988311
## 21 0.134441367 0.155493998 0.066112650 0.063711911 0.114681440
## 22 0.123982085 0.137011401 0.067793160 0.067385993 0.116449511
## 23 0.112614790 0.144272595 0.062590623 0.078298695 0.110681489
## DISTRICT
## Y E13 E18 E5
## 0 0.043322531 0.046563193 0.044345898
## 1 0.042384468 0.038556194 0.029805852
## 2 0.036357458 0.034998301 0.030581040
## 3 0.046109510 0.040922190 0.029394813
## 4 0.037617555 0.039184953 0.038401254
## 5 0.049656226 0.047364400 0.042780749
## 6 0.048501362 0.063760218 0.047956403
## 7 0.058402861 0.059892729 0.041716329
## 8 0.058103976 0.053414883 0.044648318
## 9 0.062555066 0.062026432 0.053568282
## 10 0.057456829 0.053689168 0.045996860
## 11 0.055024298 0.055337827 0.040601975
## 12 0.054626533 0.060200669 0.049052397
## 13 0.059245401 0.054568132 0.045369504
## 14 0.054368030 0.065365551 0.042131351
## 15 0.051136364 0.058928571 0.045941558
## 16 0.056969697 0.062626263 0.040673401
## 17 0.063143004 0.060442387 0.037037037
## 18 0.059763009 0.051133436 0.039799073
## 19 0.057338087 0.052139037 0.040106952
## 20 0.054887345 0.054717940 0.037438591
## 21 0.054293629 0.052446907 0.038596491
## 22 0.055781759 0.048452769 0.032573290
## 23 0.053890768 0.044465926 0.038666022
##
## DAY_OF_WEEK
## Y Friday Monday Saturday Sunday Thursday Tuesday
## 0 0.14378305 0.13849565 0.16953778 0.16851441 0.12587413 0.12553300
## 1 0.12852065 0.12031720 0.19770304 0.23543888 0.10637134 0.11375444
## 2 0.12130479 0.10363575 0.23445464 0.26231736 0.09208291 0.08019028
## 3 0.10720461 0.12219020 0.20115274 0.27435159 0.09971182 0.09913545
## 4 0.12539185 0.12774295 0.20141066 0.22257053 0.10971787 0.10344828
## 5 0.14056532 0.12146677 0.12987013 0.18334607 0.15431627 0.12223071
## 6 0.15095368 0.14495913 0.10735695 0.12806540 0.16621253 0.16076294
## 7 0.15494636 0.16299166 0.12127533 0.09505364 0.14630513 0.15941597
## 8 0.16941896 0.16472987 0.11539246 0.09133537 0.14576962 0.16085627
## 9 0.15859031 0.14801762 0.12757709 0.10907489 0.13955947 0.15947137
## 10 0.16483516 0.15808477 0.12621664 0.11601256 0.14191523 0.14348509
## 11 0.15645085 0.14939646 0.12917385 0.11600564 0.15002351 0.14955322
## 12 0.15830546 0.14353400 0.14464883 0.11928651 0.14785396 0.14130435
## 13 0.14733396 0.15060804 0.13673215 0.11973807 0.14343623 0.14795759
## 14 0.14916357 0.14203841 0.14451673 0.12252169 0.14513631 0.15040273
## 15 0.15048701 0.14480519 0.13879870 0.11461039 0.15389610 0.15974026
## 16 0.15326599 0.14976431 0.13117845 0.11299663 0.14922559 0.15973064
## 17 0.16306584 0.15483539 0.12872942 0.11754115 0.13747428 0.15457819
## 18 0.15043792 0.15378671 0.13588357 0.11360124 0.14232354 0.15417311
## 19 0.14676173 0.14750446 0.14438503 0.12329174 0.13398693 0.15240642
## 20 0.14789090 0.14839912 0.13942063 0.13366085 0.14924615 0.15331188
## 21 0.14939982 0.14330563 0.15789474 0.13130194 0.14736842 0.13277932
## 22 0.17772801 0.12764658 0.16775244 0.13823290 0.13680782 0.13070033
## 23 0.18849686 0.12421460 0.20130498 0.12010633 0.13436443 0.12228130
## DAY_OF_WEEK
## Y Wednesday
## 0 0.12826198
## 1 0.09789445
## 2 0.10601427
## 3 0.09625360
## 4 0.10971787
## 5 0.14820474
## 6 0.14168937
## 7 0.16001192
## 8 0.15249745
## 9 0.15770925
## 10 0.14945055
## 11 0.14939646
## 12 0.14506689
## 13 0.15419395
## 14 0.14622057
## 15 0.13766234
## 16 0.14383838
## 17 0.14377572
## 18 0.14979392
## 19 0.15166370
## 20 0.12807047
## 21 0.13795014
## 22 0.12113192
## 23 0.10923151
Evaluate the model by using testing set; then, check the confusion matrix
pred1 <- predict(crime_nb1, test)
confusionMatrix(table(pred1, test$HOUR))
## Confusion Matrix and Statistics
##
##
## pred1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## 0 170 62 66 37 18 15 17 25 51 77 75 78 132 103 89 57 79
## 1 66 64 70 34 19 12 13 8 17 20 35 38 38 31 24 36 40
## 2 49 62 64 20 12 4 10 14 22 16 19 22 20 28 21 21 20
## 3 1 1 2 1 1 2 0 1 1 1 1 0 1 3 0 1 0
## 4 8 10 3 7 8 8 5 6 3 4 1 3 5 2 1 1 6
## 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 6 0 0 1 1 0 0 1 1 1 1 2 0 0 0 0 0 0
## 7 26 8 7 5 4 4 12 52 74 62 44 30 18 22 14 9 17
## 8 28 16 12 11 6 16 21 55 96 83 68 53 50 55 53 51 49
## 9 38 21 19 18 10 15 23 40 77 67 82 70 69 54 53 47 77
## 10 60 48 43 24 24 29 39 44 64 90 142 111 108 119 119 83 101
## 11 13 8 10 1 4 6 6 3 14 13 14 24 22 23 21 14 14
## 12 180 74 57 31 29 15 38 66 133 201 208 242 300 219 229 213 227
## 13 19 10 13 10 9 7 3 13 26 20 25 43 37 39 38 36 38
## 14 39 22 8 10 8 3 11 20 28 28 61 50 56 57 66 64 57
## 15 2 0 1 0 0 0 0 1 0 3 1 2 1 4 1 1 3
## 16 144 78 59 37 30 38 64 115 147 170 175 188 180 209 193 212 243
## 17 147 99 90 53 40 34 54 114 169 159 177 225 221 208 238 242 306
## 18 164 134 103 54 37 37 87 111 195 207 225 241 265 236 258 221 300
## 19 17 14 9 6 3 3 14 16 14 13 15 19 11 24 22 16 18
## 20 43 23 25 16 8 9 10 15 32 30 22 23 24 31 35 29 41
## 21 63 52 41 19 20 19 19 36 57 70 76 77 82 70 90 88 79
## 22 94 44 39 22 18 13 33 49 58 57 67 66 75 63 84 70 80
## 23 56 32 26 23 9 6 5 2 10 22 21 26 26 26 28 22 32
##
## pred1 17 18 19 20 21 22 23
## 0 67 67 66 83 80 76 57
## 1 31 45 40 53 46 29 43
## 2 31 38 21 24 31 34 25
## 3 0 0 1 1 0 0 2
## 4 5 0 5 6 6 6 5
## 5 0 0 0 0 0 0 0
## 6 0 1 0 1 0 1 1
## 7 18 16 16 14 14 11 8
## 8 67 43 28 38 47 17 18
## 9 53 68 58 43 45 35 29
## 10 106 100 87 88 68 69 36
## 11 21 18 17 10 9 10 5
## 12 249 208 189 168 137 121 95
## 13 34 36 37 22 27 27 20
## 14 60 59 53 46 24 23 23
## 15 1 1 1 1 1 1 2
## 16 212 215 189 176 152 149 139
## 17 350 317 241 211 174 131 130
## 18 293 323 291 264 190 210 141
## 19 15 23 31 27 22 11 15
## 20 48 39 32 51 50 46 46
## 21 85 100 76 102 107 85 60
## 22 88 94 82 76 88 91 76
## 23 29 30 30 34 34 38 49
##
## Overall Statistics
##
## Accuracy : 0.0776
## 95% CI : (0.0746, 0.0807)
## No Information Rate : 0.0618
## P-Value [Acc > NIR] : < 2.2e-16
##
## Kappa : 0.0263
##
## Mcnemar's Test P-Value : NA
##
## Statistics by Class:
##
## Class: 0 Class: 1 Class: 2 Class: 3 Class: 4
## Sensitivity 0.119131 0.072562 0.083333 2.273e-03 0.0252366
## Specificity 0.948574 0.973075 0.980803 9.993e-01 0.9964466
## Pos Pred Value 0.103218 0.075117 0.101911 4.762e-02 0.0701754
## Neg Pred Value 0.955896 0.972078 0.976152 9.854e-01 0.9897117
## Prevalence 0.047333 0.029256 0.025474 1.459e-02 0.0105148
## Detection Rate 0.005639 0.002123 0.002123 3.317e-05 0.0002654
## Detection Prevalence 0.054630 0.028261 0.020831 6.966e-04 0.0037813
## Balanced Accuracy 0.533853 0.522818 0.532068 5.008e-01 0.5108416
## Class: 5 Class: 6 Class: 7 Class: 8 Class: 9
## Sensitivity 0.000000 2.062e-03 0.064436 0.074476 0.047383
## Specificity 1.000000 9.996e-01 0.984561 0.969334 0.963667
## Pos Pred Value NaN 8.333e-02 0.102970 0.097859 0.060306
## Neg Pred Value 0.990215 9.839e-01 0.974530 0.959098 0.953611
## Prevalence 0.009785 1.609e-02 0.026768 0.042756 0.046902
## Detection Rate 0.000000 3.317e-05 0.001725 0.003184 0.002222
## Detection Prevalence 0.000000 3.980e-04 0.016751 0.032539 0.036852
## Balanced Accuracy 0.500000 5.008e-01 0.524499 0.521905 0.505525
## Class: 10 Class: 11 Class: 12 Class: 13 Class: 14
## Sensitivity 0.09126 0.0147149 0.172315 0.023985 0.039356
## Specificity 0.94194 0.9903216 0.882811 0.980717 0.971550
## Pos Pred Value 0.07880 0.0800000 0.082667 0.066214 0.075342
## Neg Pred Value 0.95012 0.9461605 0.945662 0.946311 0.944964
## Prevalence 0.05161 0.0540998 0.057748 0.053934 0.055626
## Detection Rate 0.00471 0.0007961 0.009951 0.001294 0.002189
## Detection Prevalence 0.05977 0.0099509 0.120373 0.019537 0.029057
## Balanced Accuracy 0.51660 0.5025182 0.527563 0.502351 0.505453
## Class: 15 Class: 16 Class: 17 Class: 18 Class: 19
## Sensitivity 6.519e-04 0.13300 0.18787 0.17545 0.019485
## Specificity 9.991e-01 0.88450 0.86636 0.84937 0.987849
## Pos Pred Value 3.571e-02 0.06915 0.08475 0.07042 0.082011
## Neg Pred Value 9.491e-01 0.94053 0.94185 0.94061 0.947598
## Prevalence 5.088e-02 0.06060 0.06180 0.06107 0.052773
## Detection Rate 3.317e-05 0.00806 0.01161 0.01071 0.001028
## Detection Prevalence 9.288e-04 0.11656 0.13699 0.15215 0.012538
## Balanced Accuracy 4.999e-01 0.50875 0.52711 0.51241 0.503667
## Class: 20 Class: 21 Class: 22 Class: 23
## Sensitivity 0.033138 0.079142 0.074529 0.047805
## Specificity 0.976336 0.949090 0.950358 0.980531
## Pos Pred Value 0.070055 0.068023 0.059594 0.079545
## Neg Pred Value 0.949422 0.956430 0.960519 0.966951
## Prevalence 0.051048 0.044845 0.040500 0.033999
## Detection Rate 0.001692 0.003549 0.003018 0.001625
## Detection Prevalence 0.024148 0.052176 0.050650 0.020433
## Balanced Accuracy 0.504737 0.514116 0.512443 0.514168
crime_nb2 <- naiveBayes(UCR_PART ~ ., data=train)
crime_nb2
##
## Naive Bayes Classifier for Discrete Predictors
##
## Call:
## naiveBayes.default(x = X, y = Y, laplace = laplace)
##
## A-priori probabilities:
## Y
## Other Part One Part Three Part Two
## 0.000000000 0.003816606 0.193125175 0.499325514 0.303732706
##
## Conditional probabilities:
## OFFENSE_CODE_GROUP
## Y Aggravated Assault Aircraft Arson
##
## Other 0.000000e+00 0.000000e+00 6.681034e-02
## Part One 1.242813e-01 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 2.470966e-04 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Assembly or Gathering Violations Auto Theft
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 7.730312e-02
## Part Three 5.880899e-03 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Auto Theft Recovery Ballistics Bomb Hoax
##
## Other 8.534483e-01 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00 0.000000e+00
## Part Two 0.000000e+00 9.559660e-03 7.041109e-04
## OFFENSE_CODE_GROUP
## Y Burglary - No Property Taken Commercial Burglary
##
## Other 2.155172e-03 0.000000e+00
## Part One 0.000000e+00 2.074194e-02
## Part Three 0.000000e+00 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Confidence Games Counterfeiting Criminal Harassment
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00 0.000000e+00
## Part Two 3.263283e-02 1.432595e-02 1.218654e-03
## OFFENSE_CODE_GROUP
## Y Disorderly Conduct Drug Violation Embezzlement Evading Fare
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part Two 2.599794e-02 1.674701e-01 2.572713e-03 4.224666e-03
## OFFENSE_CODE_GROUP
## Y Explosives Fire Related Reports Firearm Discovery
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 3.294622e-05 1.181122e-02 4.365374e-03
## Part Two 1.354059e-04 9.207604e-04 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Firearm Violations Fraud Gambling Harassment
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part Two 1.787359e-02 5.941613e-02 1.083248e-04 4.110925e-02
## OFFENSE_CODE_GROUP
## Y Harbor Related Incidents HOME INVASION Homicide
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 2.427701e-03
## Part Three 1.169591e-03 0.000000e+00 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y HUMAN TRAFFICKING HUMAN TRAFFICKING - INVOLUNTARY SERVITUDE
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Investigate Person INVESTIGATE PERSON Investigate Property
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 1.183758e-01 0.000000e+00 7.020838e-02
## Part Two 0.000000e+00 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Landlord/Tenant Disputes Larceny
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 4.184590e-01
## Part Three 6.177415e-03 0.000000e+00
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Larceny From Motor Vehicle License Plate Related Incidents
##
## Other 0.000000e+00 3.879310e-02
## Part One 1.796499e-01 0.000000e+00
## Part Three 0.000000e+00 3.047525e-03
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y License Violation Liquor Violation Manslaughter
##
## Other 0.000000e+00 0.000000e+00 1.293103e-02
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 1.088872e-02 0.000000e+00 0.000000e+00
## Part Two 0.000000e+00 1.145534e-02 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Medical Assistance Missing Person Located
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00
## Part Three 1.469072e-01 3.161189e-02
## Part Two 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Missing Person Reported Motor Vehicle Accident Response
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00
## Part Three 2.434725e-02 2.346100e-01
## Part Two 4.332990e-04 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Offenses Against Child / Family Operating Under the Influence
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00
## Part Two 5.551644e-03 5.497481e-03
## OFFENSE_CODE_GROUP
## Y Other Other Burglary Phone Call Complaints
##
## Other 2.586207e-02 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 7.368287e-03 0.000000e+00
## Part Three 6.292727e-03 0.000000e+00 0.000000e+00
## Part Two 1.719656e-01 0.000000e+00 3.520555e-04
## OFFENSE_CODE_GROUP
## Y Police Service Incidents Prisoner Related Incidents
##
## Other 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00
## Part Three 1.774154e-02 8.236554e-05
## Part Two 0.000000e+00 2.031089e-03
## OFFENSE_CODE_GROUP
## Y Property Found Property Lost Property Related Damage
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 2.375422e-02 6.212009e-02 5.831480e-03
## Part Two 0.000000e+00 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Prostitution Recovered Stolen Property Residential Burglary
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 9.289152e-02
## Part Three 0.000000e+00 0.000000e+00 0.000000e+00
## Part Two 2.681038e-03 1.494882e-02 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Restraining Order Violations Robbery Search Warrants
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 7.687721e-02 0.000000e+00
## Part Three 0.000000e+00 0.000000e+00 5.831480e-03
## Part Two 1.622163e-02 0.000000e+00 0.000000e+00
## OFFENSE_CODE_GROUP
## Y Service Simple Assault Towed Vandalism
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 1.762623e-03 0.000000e+00 7.014249e-02 0.000000e+00
## Part Two 0.000000e+00 1.654119e-01 0.000000e+00 1.618101e-01
## OFFENSE_CODE_GROUP
## Y Verbal Disputes Violations Warrant Arrests
##
## Other 0.000000e+00 0.000000e+00 0.000000e+00
## Part One 0.000000e+00 0.000000e+00 0.000000e+00
## Part Three 8.195371e-02 0.000000e+00 5.480603e-02
## Part Two 0.000000e+00 6.336998e-02 0.000000e+00
##
## DISTRICT
## Y A1 A15 A7 B2
##
## Other 0.004310345 0.064655172 0.010775862 0.064655172 0.183189655
## Part One 0.004173943 0.136079049 0.020358618 0.036287746 0.140295583
## Part Three 0.006688082 0.101177827 0.021464459 0.042088790 0.155324932
## Part Two 0.005497481 0.115690841 0.017684017 0.044304826 0.163353734
## DISTRICT
## Y B3 C11 C6 D14 D4
##
## Other 0.150862069 0.144396552 0.114224138 0.043103448 0.090517241
## Part One 0.081391882 0.110694663 0.071894033 0.066740492 0.202052898
## Part Three 0.120336051 0.139329545 0.073618318 0.069368256 0.109051973
## Part Two 0.115365867 0.141228403 0.074175378 0.053241618 0.123517305
## DISTRICT
## Y E13 E18 E5
##
## Other 0.038793103 0.053879310 0.036637931
## Part One 0.059244431 0.041952383 0.028834277
## Part Three 0.053751750 0.060917552 0.046882464
## Part Two 0.054054054 0.051400097 0.040486378
##
## DAY_OF_WEEK
## Y Friday Monday Saturday Sunday Thursday Tuesday
##
## Other 0.1961207 0.1314655 0.1099138 0.1034483 0.1465517 0.1573276
## Part One 0.1551599 0.1417011 0.1471102 0.1360365 0.1412326 0.1422548
## Part Three 0.1531505 0.1431678 0.1507454 0.1371716 0.1369409 0.1412734
## Part Two 0.1520067 0.1498673 0.1378162 0.1195364 0.1445323 0.1504631
## DAY_OF_WEEK
## Y Wednesday
##
## Other 0.1551724
## Part One 0.1365050
## Part Three 0.1375504
## Part Two 0.1457780
##
## HOUR
## Y [,1] [,2]
## NA NA
## Other 12.24138 6.364888
## Part One 13.42498 6.377021
## Part Three 12.96852 6.267762
## Part Two 13.07715 6.355693
pred2 <- predict(crime_nb2, test)
confusionMatrix(factor(pred2), factor(test$UCR_PART))
## Confusion Matrix and Statistics
##
## Reference
## Prediction Other Part One Part Three Part Two
## Other 97 0 0 0
## Part One 0 5881 2 1
## Part Three 16 15 14858 32
## Part Two 1 0 89 9156
##
## Overall Statistics
##
## Accuracy : 0.9948
## 95% CI : (0.9939, 0.9956)
## No Information Rate : 0.4959
## P-Value [Acc > NIR] : < 2.2e-16
##
## Kappa : 0.9917
##
## Mcnemar's Test P-Value : NA
##
## Statistics by Class:
##
## Class: Other Class: Part One Class: Part Three
## Sensitivity 0.850877 0.9975 0.9939
## Specificity 1.000000 0.9999 0.9959
## Pos Pred Value 1.000000 0.9995 0.9958
## Neg Pred Value 0.999434 0.9994 0.9940
## Prevalence 0.003781 0.1956 0.4959
## Detection Rate 0.003217 0.1951 0.4928
## Detection Prevalence 0.003217 0.1952 0.4949
## Balanced Accuracy 0.925439 0.9987 0.9949
## Class: Part Two
## Sensitivity 0.9964
## Specificity 0.9957
## Pos Pred Value 0.9903
## Neg Pred Value 0.9984
## Prevalence 0.3048
## Detection Rate 0.3037
## Detection Prevalence 0.3067
## Balanced Accuracy 0.9961