# NOT RUN {
n <- 100
data(cc_data)
samples <- sample(1:length(cc_data$responses), n)
seqs <- sub_seqs(cc_data$seqs, samples)
y <- cc_data$responses[samples]
x <- matrix(rnorm(n*2), ncol=2)
index_test <- 91:100
index_train <- 1:90
seqs_train <- sub_seqs(seqs, index_train)
seqs_test <- sub_seqs(seqs, index_test)
actions <- unique(unlist(seqs$action_seqs))
## no covariate is used
res1 <- seqm(seqs = seqs_train, response = y[index_train],
response_type = "binary", actions=actions, K_emb = 5, K_rnn = 5,
n_epoch = 5)
pred_res1 <- predict(res1, new_seqs = seqs_test)
mean(as.numeric(pred_res1 > 0.5) == y[index_test])
## add more fully connected layers after the recurrent layer.
res2 <- seqm(seqs = seqs_train, response = y[index_train],
response_type = "binary", actions=actions, K_emb = 5, K_rnn = 5,
n_hidden=2, K_hidden=c(10,5), n_epoch = 5)
pred_res2 <- predict(res2, new_seqs = seqs_test)
mean(as.numeric(pred_res2 > 0.5) == y[index_test])
## add covariates
res3 <- seqm(seqs = seqs_train, response = y[index_train],
covariates = x[index_train, ],
response_type = "binary", actions=actions,
K_emb = 5, K_rnn = 5, n_epoch = 5)
pred_res3 <- predict(res3, new_seqs = seqs_test,
new_covariates=x[index_test, ])
## include time sequences
res4 <- seqm(seqs = seqs_train, response = y[index_train],
response_type = "binary", actions=actions,
include_time=TRUE, K_emb=5, K_rnn=5, n_epoch=5)
pred_res4 <- predict(res4, new_seqs = seqs_test)
# }
Run the code above in your browser using DataLab