-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbikesharing.R
78 lines (45 loc) · 1.51 KB
/
bikesharing.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
setwd("~/oldwork/statistics-R/")
bikeSharing <- read.csv("./data/BikeSharing.csv", header = T, stringsAsFactors = F)
View(bikeSharing)
head(bikeSharing)
str(bikeSharing)
summary(bikeSharing)
bikeSharing$datetime
as.Date(bikeSharing$datetime)
strptime(bikeSharing$datetime, "%Y-%m-%d %H:%M:%S")
datet <- strptime("2011-01-08 07:00:00", "%Y-%m-%d %H:%M:%S")
date$year + 1900
# 1900년을 0으로 시작하는 값이라서 + 1900 해주면 된다.
date$mon + 1
# 1월은 0으로 시작하는 값이라 + 1 해주면 된다.
date$mday
datet$hour
datet$min
date$sec
datet$wday
# 일요일을 0으로 시작하는 값
b <- as.Date("2018-2-25")
months(b)
weekdays(b)
hist(bikeSharing$temp)
hist(bikeSharing$atemp)
hist(bikeSharing$humidity)
hist(bikeSharing$windspeed)
hist(bikeSharing$casual)
hist(bikeSharing$registered)
View(bikeSharing)
library(MASS)
model <- lm(log(count)~season+holiday+workingday+temp+atemp+humidity+windspeed, data = bikeSharing)
summary(model)
modelAIC <- stepAIC(model, direction = "both")
results <- predict(modelAIC, newdata=test)
test <- read.csv("./bike/test.csv", header = T, stringsAsFactors = F)
results <- predict(model, newdata = subset(test, select = c('temp', 'atemp', 'humidity', 'windspeed')), type = 'response')
results
test$count <- 0
test$count <- exp(results)
test$count[test$count < 0] <- 0
test$count[test$count < 0]
submission <- test[, c('datetime', 'count')]
View(submission)
write.csv(submission, paste("./bike/submission", Sys.time(), ".csv", sep = ""), row.names = F)