-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_markdown.R
85 lines (63 loc) · 2.56 KB
/
from_markdown.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
library(plyr)
library(dplyr)
library(ggmap)
library(ggplot2)
library(readr)
library(lubridate)
library(caret)
library(knitr)
library(stringr)
train <- read_csv("./input/train.csv.zip")
#test <- read_csv("./input/train.csv.zip")
train$Resolution <- NULL
train$Descript <- NULL
options(dplyr.width = Inf)
kable(head(train))
summary(train)
sort(table(train$Category), decreasing = TRUE)
train <- mutate(train,
Year = factor(year(Dates), levels = 2003:2015),
Month = factor(month(Dates), levels = 1:12),
Day = factor(day(Dates), levels = 1:31),
Hour = factor(hour(Dates), levels = 0:23),
DayOfWeek = factor(DayOfWeek, levels=c("Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"))
)
train$Dates <- NULL
# test <- mutate(test,
# Year = factor(year(Dates), levels = 2003:2015),
# Month = factor(month(Dates), levels = 1:12),
# Day = factor(day(Dates), levels = 1:31),
# Hour = factor(hour(Dates), levels = 0:23),
# DayOfWeek = factor(DayOfWeek, levels=c("Monday",
# "Tuesday",
# "Wednesday",
# "Thursday",
# "Friday",
# "Saturday",
# "Sunday"))
# )
# test$Dates <- NULL
train$ShortAddr <- word(train$Address, start=-2, end=-1)
#test$ShortAddr <- word(test$Address, start=-2, end=-1)
#train$Address <- NULL
kable(head(train[,-6:-1]))
dummies <- dummyVars( ~ Hour + DayOfWeek, data = train)
dummy_train <- data.frame(predict(dummies, newdata= train))
dummy_train$Category <- train$Category
dummy_train$X <- train$X
dummy_train$Y <- train$Y
train <- dummy_train
#Construcción del modelo
train$Category <- make.names(train$Category)
train_partition <- createDataPartition(y=train$Category, p=.001,
list=FALSE)
training <- train[train_partition,]
testing <- train[-train_partition,]
save(training, file='crime_training.Rdata' )
save(testing, file='crime_testing.Rdata')