Learn R Programming

sparselink (version 1.0.0)

traintest: Train and test model

Description

Trains and tests prediction models

Usage

traintest(
  y_train,
  X_train,
  y_test = NULL,
  X_test = NULL,
  family = "gaussian",
  alpha = 1,
  method = c("wrap_empty", "wrap_separate", "sparselink"),
  alpha.init = 0.95,
  type = "exp",
  cands = NULL
)

Value

Returns a list with the computation time in slot time, the out-of-sample deviance in slot deviance, the out-of-sample ROC-AUC in slot auc, the coefficients in slot coef, the predicted value in slot y_hat, and the optimal hyperparameters in slot hyperpar.

Arguments

y_train

target of training samples: \(n \times q\) matrix (multi-task learning) or list of \(q\) vectors of length \(n_1,\ldots,n_q\) (transfer learning)

X_train

features of training samples: \(n \times p\) matrix (multi-task learning) or list of \(q\) matrices of dimensions \(n_1 \times p,\ldots,n_q \times p\) (transfer learning)

y_test

target of testing samples: \(m \times p\) matrix (multi-task learning) or list of \(q\) vectors of length \(m_1,\ldots,m_q\) (transfer learning)

X_test

features of testing samples: \(m \times p\) matrix (multi-task learning) or list of \(q\) matrices of dimensions \(m_1 \times p,\ldots,m_q \times p\) (transfer learning)

family

character "gaussian" or "binomial"

alpha

elastic net mixing parameter of final regressions, default: 1 (lasso)

alpha.init

elastic net mixing parameter for initial regressions, default: 0.95 (lasso-like elastic net)

type

default "exp" scales weights with \(w_{ext}^{v_{ext}}+w_{int}^{v_{int}}\) (see internal function construct_penfacs for details)

cands

candidate values for both scaling parameters, default: NULL ({0, 0.2, 0.4, 0.6, 0.8, 1})

Examples

Run this code
#--- multi-task learning ---
# \donttest{
family <- "gaussian"
data <- sim_data_multi(family=family)
result <- traintest(data$y_train,data$X_train,family=family)# }

#--- transfer learning ---
# \donttest{
family <- "gaussian"
data <- sim_data_trans(family=family)
result <- traintest(data$y_train,data$X_train,family=family)# }

Run the code above in your browser using DataLab