Created
June 15, 2015 21:35
-
-
Save gghatano/64568fab7971486e3b70 to your computer and use it in GitHub Desktop.
Rmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dummiesでダミー変数を作る | |
======================================================== | |
```{r} | |
library(data.table) | |
library(dplyr) | |
library(dummies) | |
dat = fread("data.csv") | |
dat %>% head | |
``` | |
```{r} | |
dat.dummy = dat %>% | |
mutate(hour = hour(datetime)) %>% | |
mutate(hour = as.factor(hour)) %>% | |
mutate(season = as.factor(season)) %>% | |
mutate(holiday = as.factor(holiday)) %>% | |
mutate(workingday = as.factor(workingday)) %>% | |
mutate(weather = as.factor(weather)) %>% | |
select(-datetime) %>% | |
dummy.data.frame() | |
library(glmnet) | |
dat.dummy.mat = | |
dat.dummy %>% | |
select(-hour23, -weather4, -holiday1, -workingday1, -season4) %>% | |
select(-casual, -registered, -count) %>% as.matrix | |
dat.dummy.count = | |
dat.dummy %>% select(count) %>% unlist | |
dat.dummy.mat %>% head | |
glm_res = | |
glmnet(dat.dummy.mat, dat.dummy.count, family = "poisson", alpha = 0.1) | |
glm_res | |
predict(glm_res, dat.dummy.mat) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment