Skip to content

Commit

Permalink
Renamed Cherry Hill to Federal Hill
Browse files Browse the repository at this point in the history
  • Loading branch information
BuzzdAldrin committed Aug 17, 2018
1 parent a0e2109 commit 5d4d9fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
3 changes: 2 additions & 1 deletion data_cleaning.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2"

Let's begin by loading the three data files in. Note that this data is from fall 2017.
We have data on: calls, arrests, and victims. Calls is a very large file, and arrests has pretty messy data, so we'll do a separate rmd of EDA on those.

```{r importing data}
victims <- read.csv("Data/BPD_Part_1_Victim_Based_Crime_Data.csv")
```
Expand Down Expand Up @@ -354,7 +355,7 @@ victims$Location.1 <- NULL
rm(latLon)
```

####Weapons
#### Weapons

```{r}
#Grab em
Expand Down
43 changes: 22 additions & 21 deletions cherryHillExploration.rmd → federalHillExploration.rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "An Analysis of Crime in Cherry Hill"
title: "An Analysis of Crime in Federal Hill"
author: "Jason Hammett"
date: "February 15, 2018"
output: html_document
Expand Down Expand Up @@ -39,54 +39,55 @@ cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2"
#scale_colour_manual(values=cbPalette)
```

## Cherry Hill: A Neighborhood Level Analysis
## Federal Hill: A Neighborhood Level Analysis


To begin, I'll load the data cleaned in data_cleaning.rmd

```{r data import}
load("cleanedData.RData")
```


I'll grab the cherryHill neighborhood from the data set
```{r cherryHill}
cherryHill <- victims[which(victims$Neighborhood == "Cherry Hill"),]
I'll grab the Federal Hill neighborhood from the data set
```{r federalHill}
federalHill <- victims[which(victims$Neighborhood == "Federal Hill"),]
```

I'm going to utilize ggmap to visualize these crimes.
```{r mapping cherry hill}
#Grab a map centered on the cherry hill neighborhood
cherryHillMap <- get_map("cherry hill, baltimore, maryland", zoom = 15)
```{r mapping federal hill}
#Grab a map centered on the federal hill neighborhood
federalHillMap <- get_map("federal hill, baltimore, maryland", zoom = 16)
#Plot all crimes
mapPoints <- ggmap(cherryHillMap) + geom_point(aes(x = Longitude, y = Latitude), data = cherryHill, alpha = .25)
mapPoints <- ggmap(federalHillMap) + geom_point(aes(x = Longitude, y = Latitude), data = federalHill, alpha = .25)
#Titles
mapPoints <- mapPoints + ggtitle("Crime in Cherry Hill") + ylab("Latitude") + xlab("Longitude")
mapPoints <- mapPoints + ggtitle("Crime in Federal Hill") + ylab("Latitude") + xlab("Longitude")
#Display it
mapPoints
mapPoints2 <- ggmap(cherryHillMap) + geom_point(aes(x = Longitude, y = Latitude, colour = Weapon), data = cherryHill, alpha = .75) + scale_colour_manual(values=cbbPalette)
mapPoints2 <- mapPoints2 + ggtitle("Crime in Cherry Hill by Weapon Used") + ylab("Latitude") + xlab("Longitude")
mapPoints2 <- ggmap(federalHillMap) + geom_point(aes(x = Longitude, y = Latitude, colour = Weapon), data = federalHill, alpha = .75) + scale_colour_manual(values=cbbPalette)
mapPoints2 <- mapPoints2 + ggtitle("Crime in Federal Hill by Weapon Used") + ylab("Latitude") + xlab("Longitude")
#Display
mapPoints2
```

Basic rpart decision tree on the cherryhill neighborhood.
Basic rpart decision tree on the Federal Hill neighborhood.

```{r training tree on cherry hill}
```{r training tree on federal hill}
#Form a 90-10 train test split
split <- sample(nrow(cherryHill), nrow(cherryHill) * 0.9)
split <- sample(nrow(federalHill), nrow(federalHill) * 0.9)
#Divide the set into train and test
cherryHillTrain <- cherryHill[split,]
cherryHillTest <- cherryHill[-split,]
federalHillTrain <- federalHill[split,]
federalHillTest <- federalHill[-split,]
#Build the model
cherryHillModel <- rpart(cherryHillTrain, formula = CrimeCode ~ Description)
federalHillModel <- rpart(federalHillTrain, formula = CrimeCode ~ Description)
#Plot it
prp(cherryHillModel)
prp(federalHillModel)
#Make two more models
cherryHillModel2 <- rpart(cherryHillTrain, formula = Weapon ~ Description)
prp(cherryHillModel2)
federalHillModel2 <- rpart(federalHillTrain, formula = Weapon ~ Description)
prp(federalHillModel2)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

0 comments on commit 5d4d9fc

Please sign in to comment.