# Load the synthetic data
data(ClassificationExample)
tree.org <- ClassificationExample$tree.org # original tree structure
x2.org <- ClassificationExample$x.org # original design matrix
x1 <- ClassificationExample$x1
y <- ClassificationExample$y # response
# Do the tree-guided expansion
expand.data <- getetmat(tree.org, x2.org)
x2 <- expand.data$x.expand # expanded design matrix
tree.expand <- expand.data$tree.expand # expanded tree structure
# Do train-test split
idtrain <- 1:200
x1.train <- as.matrix(x1[idtrain, ])
x2.train <- x2[idtrain, ]
y.train <- y[idtrain, ]
x1.test <- as.matrix(x1[-idtrain, ])
x2.test <- x2[-idtrain, ]
y.test <- y[-idtrain, ]
# specify some model parameters
set.seed(100)
control <- list(maxit = 100, mu = 1e-3, tol = 1e-5, verbose = FALSE)
modstr <- list(nlambda = 5, alpha = seq(0, 1, length.out = 5))
simu.cv <- cv.TSLA(y = y.train, as.matrix(x1[idtrain, ]),
X_2 = x2.train,
treemat = tree.expand, family = 'logit',
penalty = 'CL2', pred.loss = 'AUC',
gamma.init = NULL, weight = c(1, 1), nfolds = 5,
group.weight = NULL, feature.weight = NULL,
control = control, modstr = modstr)
# Do prediction with the selected tuning parameters on the test set. Report AUC on the test set.
rmid <- simu.cv$TSLA.fit$rmid # remove all zero columns
if(length(rmid) > 0){
x2.test <- x2.test[, -rmid]}
y.new <- predict_cvTSLA(simu.cv, as.matrix(x1[-idtrain, ]), x2.test)
library(pROC)
auc(as.vector(y.test), as.vector(y.new))
Run the code above in your browser using DataLab