Title: | The (Adaptive) LASSO and Elastic Net Penalized Least Squares, Logistic Regression, Hybrid Huberized Support Vector Machines, Squared Hinge Loss Support Vector Machines and Expectile Regression using a Fast Generalized Coordinate Descent Algorithm |
---|---|
Description: | Implements a generalized coordinate descent (GCD) algorithm for computing the solution paths of the hybrid Huberized support vector machine (HHSVM) and its generalizations. Supported models include the (adaptive) LASSO and elastic net penalized least squares, logistic regression, HHSVM, squared hinge loss SVM and expectile regression. |
Authors: | Yi Yang <[email protected]>, Yuwen Gu <[email protected]>, Hui Zou <[email protected]> |
Maintainer: | Yi Yang <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.6 |
Built: | 2024-11-06 06:23:49 UTC |
Source: | CRAN |
coef
is a generic function which extracts model coefficients from
objects returned by modeling functions. coefficients
is an
alias for it.
coef(object, ...)
coef(object, ...)
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Coefficients extracted from the model object object
.
coef.gcdnet
, coef.erpath
,
coef.lspath
, coef.hsvmpath
,
coef.logitpath
, coef.sqsvmpath
.
This function gets coefficients or makes coefficient predictions from a
cross-validated gcdnet model, using the stored "gcdnet.fit"
object,
and the optimal value chosen for lambda
.
## S3 method for class 'cv.gcdnet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.gcdnet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to get coefficients or make coefficient predictions.
The object returned depends the ... argument which is passed on
to the predict
method for gcdnet
objects.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
cv.gcdnet
, and predict.cv.gcdnet
methods.
data(FHT) set.seed(2011) cv <- cv.gcdnet(FHT$x, FHT$y, lambda2 = 1, nfolds = 5) coef(cv, s = "lambda.min")
data(FHT) set.seed(2011) cv <- cv.gcdnet(FHT$x, FHT$y, lambda2 = 1, nfolds = 5) coef(cv, s = "lambda.min")
Computes the coefficients or returns a list of the indices of the nonzero
coefficients at the requested values for lambda
from a fitted
gcdnet
object.
## S3 method for class 'gcdnet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
## S3 method for class 'gcdnet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
type |
type |
... |
not used. Other arguments to predict. |
s
is the new vector at which predictions are requested. If s
is not in the lambda sequence used for fitting the model, the coef
function will use linear interpolation to make predictions. The new values
are interpolated using a fraction of coefficients from both left and right
lambda
indices.
The object returned depends on type.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
predict.gcdnet
method
data(FHT) fit1 <- gcdnet(x = FHT$x,y = FHT$y) coef(fit1, type = "coef", s = c(0.1,0.005)) coef(fit1, type = "nonzero")
data(FHT) fit1 <- gcdnet(x = FHT$x,y = FHT$y) coef(fit1, type = "coef", s = c(0.1,0.005)) coef(fit1, type = "nonzero")
Does k-fold cross-validation for gcdnet, produces a plot, and returns a
value for lambda
. This function is modified based on the cv
function from the glmnet
package.
cv.gcdnet( x, y, lambda = NULL, pred.loss = c("misclass", "loss"), nfolds = 5, foldid, delta = 2, omega = 0.5, ... )
cv.gcdnet( x, y, lambda = NULL, pred.loss = c("misclass", "loss"), nfolds = 5, foldid, delta = 2, omega = 0.5, ... )
x |
|
y |
response variable or class label |
lambda |
optional user-supplied lambda sequence; default is
|
pred.loss |
loss function to use for cross-validation error. Valid options are:
Default is
|
nfolds |
number of folds - default is 5. Although |
foldid |
an optional vector of values between 1 and |
delta |
parameter |
omega |
parameter |
... |
other arguments that can be passed to gcdnet. |
The function runs gcdnet
nfolds
+1 times; the first to
get the lambda
sequence, and then the remainder to compute the fit
with each of the folds omitted. The average error and standard deviation
over the folds are computed.
an object of class cv.gcdnet
is returned, which is a
list with the ingredients of the cross-validation fit.
lambda |
the
values of |
cvm |
the mean
cross-validated error - a vector of length |
cvsd |
estimate of standard error of |
cvupper |
upper curve = |
cvlower |
lower curve
= |
nzero |
number of non-zero coefficients at each
|
name |
a text string indicating type of measure (for plotting purposes). |
gcdnet.fit |
a fitted |
lambda.min |
The optimal value of
|
lambda.1se |
The largest value of |
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang
<[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
gcdnet
, plot.cv.gcdnet
,
predict.cv.gcdnet
, and coef.cv.gcdnet
methods.
# fit an elastic net penalized HHSVM with lambda2 = 0.1 for the L2 penalty. # Use the misclassification rate as the cross validation prediction loss. # Use five-fold CV to choose the optimal lambda for the L1 penalty. data(FHT) set.seed(2011) cv <- cv.gcdnet(FHT$x, FHT$y, method = "hhsvm", lambda2 = 0.1, pred.loss = "misclass", nfolds = 5, delta = 1.5) plot(cv) # fit an elastic net penalized least squares # with lambda2 = 0.1 for the L2 penalty. Use the # least square loss as the cross validation # prediction loss. Use five-fold CV to choose # the optimal lambda for the L1 penalty. set.seed(2011) cv1 <- cv.gcdnet(FHT$x, FHT$y_reg, method ="ls", lambda2 = 0.1, pred.loss = "loss", nfolds = 5) plot(cv1) # To fit a LASSO penalized logistic regression # we set lambda2 = 0 to disable the L2 penalty. Use the # logistic loss as the cross validation # prediction loss. Use five-fold CV to choose # the optimal lambda for the L1 penalty. set.seed(2011) cv2 <- cv.gcdnet(FHT$x, FHT$y, method ="logit", lambda2 = 0, pred.loss="loss", nfolds=5) plot(cv2)
# fit an elastic net penalized HHSVM with lambda2 = 0.1 for the L2 penalty. # Use the misclassification rate as the cross validation prediction loss. # Use five-fold CV to choose the optimal lambda for the L1 penalty. data(FHT) set.seed(2011) cv <- cv.gcdnet(FHT$x, FHT$y, method = "hhsvm", lambda2 = 0.1, pred.loss = "misclass", nfolds = 5, delta = 1.5) plot(cv) # fit an elastic net penalized least squares # with lambda2 = 0.1 for the L2 penalty. Use the # least square loss as the cross validation # prediction loss. Use five-fold CV to choose # the optimal lambda for the L1 penalty. set.seed(2011) cv1 <- cv.gcdnet(FHT$x, FHT$y_reg, method ="ls", lambda2 = 0.1, pred.loss = "loss", nfolds = 5) plot(cv1) # To fit a LASSO penalized logistic regression # we set lambda2 = 0 to disable the L2 penalty. Use the # logistic loss as the cross validation # prediction loss. Use five-fold CV to choose # the optimal lambda for the L1 penalty. set.seed(2011) cv2 <- cv.gcdnet(FHT$x, FHT$y, method ="logit", lambda2 = 0, pred.loss="loss", nfolds=5) plot(cv2)
The FHT
data set has n = 50 observations and p = 100 predictors. The
covariance between predictors Xj and Xj' has the same correlation 0.5. See
details in Friedman et al. (2010).
This data frame contains the following columns:
a matrix with 100 rows and 5000 columns
class labels
response variable for regression
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
data(FHT)
data(FHT)
Fits a regularization path for large margin classifiers at a sequence of regularization parameters lambda.
gcdnet( x, y, nlambda = 100, method = c("hhsvm", "logit", "sqsvm", "ls", "er"), lambda.factor = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf = rep(1, nvars), pf2 = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = FALSE, intercept = TRUE, eps = 1e-08, maxit = 1e+06, delta = 2, omega = 0.5 )
gcdnet( x, y, nlambda = 100, method = c("hhsvm", "logit", "sqsvm", "ls", "er"), lambda.factor = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf = rep(1, nvars), pf2 = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = FALSE, intercept = TRUE, eps = 1e-08, maxit = 1e+06, delta = 2, omega = 0.5 )
x |
matrix of predictors, of dimension |
y |
response variable. This argument should be a two-level factor for classification. |
nlambda |
the number of |
method |
a character string specifying the loss function to use, valid options are:
Default is |
lambda.factor |
The factor for getting the minimal lambda in
|
lambda |
a user supplied |
lambda2 |
regularization parameter |
pf |
L1 penalty factor of length |
pf2 |
L2 penalty factor of length |
exclude |
indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor. |
dfmax |
limit the maximum number of variables in the model. Useful for
very large |
pmax |
limit the maximum number of variables ever to be nonzero. For
example once |
standardize |
logical flag for variable standardization, prior to
fitting the model sequence. If |
intercept |
logical flag to indicate whether to include or exclude the intercept in the model. |
eps |
convergence threshold for coordinate majorization descent. Each
inner coordinate majorization descent loop continues until the relative
change in any coefficient (i.e., |
maxit |
maximum number of outer-loop iterations allowed at fixed lambda
value. Default is 1e6. If models do not converge, consider increasing
|
delta |
the parameter |
omega |
the parameter |
Note that the objective function in gcdnet
is
where the penalty is a combination of L1 and L2
term. Users can specify the loss function to use, options include
Huberized squared hinge loss, Squared hinge loss, least square loss,
logistic regression and expectile regression loss. Users can also tweak
the penalty by choosing different and penalty factor.
For computing speed reason, if models are not converging or running slow,
consider increasing eps
, decreasing nlambda
, or increasing
lambda.factor
before increasing maxit
.
FAQ:
Question: “I couldn't get an idea how to specify an option to get adaptive LASSO, how to specify an option to get elastic net and adaptive elastic net? Could you please give me a quick hint?”
Answer: lambda2
is the regularize parameter for L2 penalty
part. To use LASSO, set lambda2=0
. To use elastic net, set
lambda2
as nonzero.
pf
is the L1 penalty factor of length (
is the
number of predictors). Separate L1 penalty weights can be applied to each
coefficient to allow differential L1 shrinkage. Similiarly
pf2
is
the L2 penalty factor of length .
To use adaptive LASSO, you should set lambda2=0
and also specify
pf
and pf2
. To use adaptive elastic net, you should set
lambda2
as nonzero and specify pf
and pf2
,
For example:
library('gcdnet') # Dataset N = 100, p = 10 x_log <- matrix(rnorm(100*10),100,10) y_log <- sample(c(-1,1),100,replace=TRUE) # LASSO m <- gcdnet(x=x_log,y=y_log,lambda2=0,method="log") plot(m) # elastic net with lambda2 = 1 m <- gcdnet(x=x_log,y=y_log,lambda2=1,method="log") plot(m) # adaptive lasso with penalty factor # pf = 0.5 0.5 0.5 0.5 0.5 1.0 1.0 1.0 1.0 1.0 m <- gcdnet(x=x_log,y=y_log,lambda2=0,method="log", pf=c(rep(0.5,5),rep(1,5))) plot(m) # adaptive elastic net with lambda2 = 1 and penalty factor pf = # c(rep(0.5,5),rep(1,5)) pf2 = 3 3 3 3 3 1 1 1 1 1 m <- gcdnet(x=x_log,y=y_log,lambda2=1,method="log", pf=c(rep(0.5,5),rep(1,5)), pf2 = c(rep(3,5),rep(1,5))) plot(m)
Question: “what is the meaning of the parameter
pf
? On the package documentation, it said pf
is the penalty
weight applied to each coefficient of beta?”
Answer: Yes, pf
and pf2
are L1 and L2 penalty factor
of length used for adaptive LASSO or adaptive elastic net. 0
means that the feature (variable) is always excluded, 1 means that the
feature (variable) is included with weight 1.
Question: “Does gcdnet deal with both continuous and categorical response variables?”
Answer: Yes, both are supported, you can use a continuous type response variable with the least squares regression loss, or a categorical type response with losses for classification problem.
Question: “Why does predict function not work? predict should return the predicted probability of the positive class. Instead I get:”
Error in as.matrix(as.matrix(cbind2(1, newx)) %*% nbeta): error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in t(.Call(Csparse_dense_crossprod, y, t(x))): error in evaluating the argument 'x' in selecting a method for function 't': Error: Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90?
“Using the Arcene dataset and executing the following code will give the above error:”
library(gcdnet) arc <- read.csv("arcene.csv", header=FALSE) fit <- gcdnet(arc[,-10001], arc[,10001], standardize=FALSE, method="logit") pred <- rnorm(10000) predict(fit, pred, type="link")
Answer: It is actually NOT a bug of gcdnet. When make prediction using a new matrix x, each observation of x should be arranged as a row of a matrix. In your code, because "pred" is a vector, you need to convert "pred" into a matrix, try the following code:
pred <- rnorm(10000) pred <- matrix(pred,1,10000) predict(fit, pred, type="link")
An object with S3 class gcdnet
.
call |
the call that produced this object |
b0 |
intercept sequence of length
|
beta |
a |
lambda |
the actual sequence of |
df |
the number of nonzero coefficients for each value of
|
dim |
dimension of coefficient matrix (ices) |
npasses |
total number of iterations (the most inner loop) summed over all lambda values |
jerr |
error flag, for warnings and errors, 0 if no error. |
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
plot.gcdnet
data(FHT) # 1. solution paths for the LASSO penalized least squares. # To use LASSO set lambda2 = 0. m1 <- gcdnet(x = FHT$x, y = FHT$y_reg, lambda2 = 0, method = "ls") plot(m1) # 2. solution paths for the elastic net penalized HHSVM. # lambda2 is the parameter controlling the L2 penalty. m2 <- gcdnet(x = FHT$x, y = FHT$y, delta = 1, lambda2 = 1, method = "hhsvm") plot(m2) # 3. solution paths for the adaptive LASSO penalized SVM # with the squared hinge loss. To use the adaptive LASSO, # set lambda2 = 0 and meanwhile specify the L1 penalty weights. p <- ncol(FHT$x) # set the first three L1 penalty weights as 0.1 and the rest are 1 pf = c(0.1, 0.1, 0.1, rep(1, p-3)) m3 <- gcdnet(x = FHT$x, y = FHT$y, pf = pf, lambda2 = 0, method = "sqsvm") plot(m3) # 4. solution paths for the adaptive elastic net penalized # logistic regression. p <- ncol(FHT$x) # set the first three L1 penalty weights as 10 and the rest are 1. pf <- c(10, 10, 10, rep(1, p-3)) # set the last three L2 penalty weights as 0.1 and the rest are 1. pf2 <- c(rep(1, p-3), 0.1, 0.1, 0.1) # set the L2 penalty parameter lambda2=0.01. m4 <- gcdnet(x = FHT$x, y = FHT$y, pf = pf, pf2 = pf2, lambda2 = 0.01, method = "logit") plot(m4) # 5. solution paths for the LASSO penalized expectile regression # with the asymmetric least square parameter omega=0.9. m5 <- gcdnet(x = FHT$x, y = FHT$y_reg, omega = 0.9, lambda2 = 0, method = "er") plot(m5)
data(FHT) # 1. solution paths for the LASSO penalized least squares. # To use LASSO set lambda2 = 0. m1 <- gcdnet(x = FHT$x, y = FHT$y_reg, lambda2 = 0, method = "ls") plot(m1) # 2. solution paths for the elastic net penalized HHSVM. # lambda2 is the parameter controlling the L2 penalty. m2 <- gcdnet(x = FHT$x, y = FHT$y, delta = 1, lambda2 = 1, method = "hhsvm") plot(m2) # 3. solution paths for the adaptive LASSO penalized SVM # with the squared hinge loss. To use the adaptive LASSO, # set lambda2 = 0 and meanwhile specify the L1 penalty weights. p <- ncol(FHT$x) # set the first three L1 penalty weights as 0.1 and the rest are 1 pf = c(0.1, 0.1, 0.1, rep(1, p-3)) m3 <- gcdnet(x = FHT$x, y = FHT$y, pf = pf, lambda2 = 0, method = "sqsvm") plot(m3) # 4. solution paths for the adaptive elastic net penalized # logistic regression. p <- ncol(FHT$x) # set the first three L1 penalty weights as 10 and the rest are 1. pf <- c(10, 10, 10, rep(1, p-3)) # set the last three L2 penalty weights as 0.1 and the rest are 1. pf2 <- c(rep(1, p-3), 0.1, 0.1, 0.1) # set the L2 penalty parameter lambda2=0.01. m4 <- gcdnet(x = FHT$x, y = FHT$y, pf = pf, pf2 = pf2, lambda2 = 0.01, method = "logit") plot(m4) # 5. solution paths for the LASSO penalized expectile regression # with the asymmetric least square parameter omega=0.9. m5 <- gcdnet(x = FHT$x, y = FHT$y_reg, omega = 0.9, lambda2 = 0, method = "er") plot(m5)
Plots the cross-validation curve, and upper and lower standard deviation
curves, as a function of the lambda
values used. This function is
modified based on the plot.cv
function from the glmnet
package.
## S3 method for class 'cv.gcdnet' plot(x, sign.lambda = 1, ...)
## S3 method for class 'cv.gcdnet' plot(x, sign.lambda = 1, ...)
x |
fitted |
sign.lambda |
either plot against |
... |
other graphical parameters to plot |
A plot is produced.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
# fit an elastic net penalized logistic regression with lambda2 = 1 for the # L2 penalty. Use the logistic loss as the cross validation prediction loss. # Use five-fold CV to choose the optimal lambda for the L1 penalty. data(FHT) set.seed(2011) cv=cv.gcdnet(FHT$x, FHT$y, method ="logit", lambda2 = 1, pred.loss="loss", nfolds=5) plot(cv)
# fit an elastic net penalized logistic regression with lambda2 = 1 for the # L2 penalty. Use the logistic loss as the cross validation prediction loss. # Use five-fold CV to choose the optimal lambda for the L1 penalty. data(FHT) set.seed(2011) cv=cv.gcdnet(FHT$x, FHT$y, method ="logit", lambda2 = 1, pred.loss="loss", nfolds=5) plot(cv)
Produces a coefficient profile plot of the coefficient paths for a fitted
gcdnet
object. This function is modified based on the
plot
function from the glmnet
package.
## S3 method for class 'gcdnet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
## S3 method for class 'gcdnet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
x |
fitted |
xvar |
what is on the X-axis. |
color |
if |
label |
if |
... |
other graphical parameters to plot |
A coefficient profile plot is produced.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang
<[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
data(FHT) m1 <- gcdnet(x = FHT$x,y = FHT$y) par(mfrow = c(1,3)) plot(m1) # plots against the L1-norm of the coefficients plot(m1,xvar = "lambda",label = TRUE) # plots against the log-lambda sequence plot(m1,color = TRUE)
data(FHT) m1 <- gcdnet(x = FHT$x,y = FHT$y) par(mfrow = c(1,3)) plot(m1) # plots against the L1-norm of the coefficients plot(m1,xvar = "lambda",label = TRUE) # plots against the log-lambda sequence plot(m1,color = TRUE)
predict
is a generic function for predictions from the results of
various model fitting functions. The function invokes particular
methods which depend on the class
of the first
argument.
predict(object, ...)
predict(object, ...)
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
The form of the value returned by predict
depends on the
class of its argument. See the documentation of the particular methods for
details of what is produced by that method.
predict.gcdnet
, predict.erpath
,
predict.lspath
, predict.hsvmpath
,
predict.logitpath
, predict.sqsvmpath
.
This function makes predictions from a cross-validated gcdnet model, using
the stored "gcdnet.fit"
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.gcdnet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.gcdnet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to make a prediction.
The object returned depends the ... argument which is passed on
to the predict
method for gcdnet
objects.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
cv.gcdnet
, and coef.cv.gcdnet
methods.
data(FHT) set.seed(2011) cv=cv.gcdnet(FHT$x, FHT$y, lambda2 = 1, pred.loss="misclass", lambda.factor=0.05, nfolds=5) pre = predict(cv$gcdnet.fit, newx = FHT$x, s = cv$lambda.1se, type = "class")
data(FHT) set.seed(2011) cv=cv.gcdnet(FHT$x, FHT$y, lambda2 = 1, pred.loss="misclass", lambda.factor=0.05, nfolds=5) pre = predict(cv$gcdnet.fit, newx = FHT$x, s = cv$lambda.1se, type = "class")
Similar to other predict methods, this functions predicts fitted values and
class labels from a fitted gcdnet
object.
## S3 method for class 'gcdnet' predict(object, newx, s = NULL, type = c("class", "link"), ...)
## S3 method for class 'gcdnet' predict(object, newx, s = NULL, type = c("class", "link"), ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
type |
type of prediction required.
|
... |
Not used. Other arguments to predict. |
s
is the new vector at which predictions are requested. If s
is not in the lambda sequence used for fitting the model, the
predict
function will use linear interpolation to make predictions.
The new values are interpolated using a fraction of predicted values from
both left and right lambda
indices.
The object returned depends on type.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
coef
method
data(FHT) m1 <- gcdnet(x = FHT$x,y = FHT$y) print(predict(m1, type = "class",newx = FHT$x[2:5, ]))
data(FHT) m1 <- gcdnet(x = FHT$x,y = FHT$y) print(predict(m1, type = "class",newx = FHT$x[2:5, ]))
Print a summary of the gcdnet path at each step along the path.
## S3 method for class 'gcdnet' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'gcdnet' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
fitted |
digits |
significant digits in printout |
... |
additional print arguments |
The call that produced the gcdnet
object is printed, followed
by a two-column matrix with columns Df
and Lambda
. The
Df
column is the number of nonzero coefficients.
a two-column matrix, the first columns is the number of nonzero
coefficients and the second column is Lambda
.
Yi Yang, Yuwen Gu and Hui Zou
Maintainer: Yi Yang <[email protected]>
Yang, Y. and Zou, H. (2012).
"An Efficient Algorithm for Computing The HHSVM and Its Generalizations."
Journal of Computational and Graphical Statistics, 22, 396-415.
BugReport: https://github.com/emeryyi/gcdnet
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
Friedman, J., Hastie, T., and Tibshirani, R. (2010).
"Regularization paths for generalized linear models via coordinate descent."
Journal of Statistical Software, 33, 1.
https://www.jstatsoft.org/v33/i01/
data(FHT) m1 <- gcdnet(x = FHT$x, y = FHT$y, delta = 1, lambda2 = 0.1) print(m1)
data(FHT) m1 <- gcdnet(x = FHT$x, y = FHT$y, delta = 1, lambda2 = 0.1) print(m1)