Performs K-fold cross-validation to select the regularization parameter for
picasso models. Multinomial models use a fixed full-data class map and
softmax negative log-likelihood or misclassification loss.
cv.picasso(X, Y, ..., nfolds = 10, foldid = NULL,
type.measure = "default", fast.mode = FALSE)# S3 method for cv.picasso
print(x, ...)
# S3 method for cv.picasso
plot(x, sign.lambda = 1, ...)
# S3 method for cv.picasso
coef(object, s = c("lambda.min", "lambda.1se"), ...)
# S3 method for cv.picasso
predict(object, newdata, s = c("lambda.min", "lambda.1se"),
type = "response", ...)
cv.picasso returns an object of class "cv.picasso" with components:
Ordered lambda sequence evaluated by every fold. A generated full-data fit may first stop normally and thereby establish a shorter path; every fold must then cover that fixed sequence completely.
Mean cross-validated error for each lambda.
Standard error of the mean cross-validated error.
Upper and lower error-bar bounds.
Number of nonzero coefficients at each lambda. For multinomial models this is the total across all classes.
Lambda that minimises cvm.
Largest lambda within one standard error of the minimum.
Name of the loss measure used.
Fold assignment used for each observation.
Model family.
Logical precision preset used for all fits.
Effective convergence tolerance used for all fits.
Full-data picasso fit.
print.cv.picasso returns its input invisibly, and
plot.cv.picasso draws the CV curve and returns NULL invisibly.
coef.cv.picasso and predict.cv.picasso return the corresponding
underlying fit-method result at lambda.min or lambda.1se.
Numeric design matrix, \(n \times d\).
Response vector. A one-column Gaussian response matrix is accepted for compatibility.
Additional arguments passed to picasso.
Number of cross-validation folds. Default is 10.
Optional integer vector of fold assignments (length \(n\)).
Labels must be consecutive positive integers starting at one. If
NULL, assignments are generated randomly; binomial and multinomial
assignments are stratified by class. (The Python
cross_validate counterpart instead expects zero-based labels,
matching its zero-based lambda indices.)
Loss measure for cross-validation. "default"
uses "class" for binomial and multinomial models and
"deviance" otherwise. Multinomial models support only
"class" and "deviance".
Additional options: "mse", "mae", "deviance",
"class". MSE and MAE are evaluated on the response scale: fitted
probabilities for binomial models and fitted means for Poisson models.
Logical precision preset passed consistently to the
full-data and fold fits. With the default FALSE, prec
defaults to 1e-7 but may be supplied through ...;
TRUE uses the benchmark-calibrated fast tolerance 4e-4 for
Poisson and 1e-4 for other non-Gaussian families. Gaussian retains
its glmnet-aligned 1e-7 objective-change tolerance.
A "cv.picasso" object.
A "cv.picasso" object.
Which lambda to use: "lambda.min" (default) selects the
lambda that minimises CV error; "lambda.1se" uses the largest
lambda within one standard error of the minimum.
Multiplier for the x-axis of the CV plot (1 for
\(\log(\lambda)\), -1 for \(-\log(\lambda)\)). Zero lambda
values are displayed at a finite position below the positive path.
Matrix of new observations for prediction.
Prediction type; passed to the underlying predict
method.
Jason Ge, Xingguo Li, Haoming Jiang, Mengdi Wang, Tong Zhang, Han Liu and Tuo Zhao
Maintainer: Tuo Zhao <tourzhao@gatech.edu>
Every binomial or multinomial training fold must contain every class observed
in the full data; automatic stratification therefore requires at least two
observations per class. A custom foldid that violates this rule or a
failed, truncated, or otherwise unusable fold fit produces an explicit error
rather than silently omitting the fold. Normal deviance-tail stopping may
shorten the initial full-data generated path; that retained path is then
passed explicitly to every fold and must be covered in full.
An unusually deep scalar path can make a training fold reach normal
saturation before completing that fixed sequence. This is reported as a
truncated-fold error; request fewer lambdas or a larger
lambda.min.ratio when it occurs.
Binomial factor responses use the full-data two-level map in every fold and
are scored as zero/one outcomes. When predicting from an offset-fitted
binomial or Poisson cv.picasso object, pass newoffset through
... to the underlying prediction method.
For Gaussian models, the full-data type.gaussian = "auto" decision is
also reused in every fold, so changing training-fold sample sizes cannot switch
the native backend.
picasso
set.seed(1)
n <- 100; d <- 50
X <- matrix(rnorm(n * d), n, d)
Y <- X[, 1:5] %*% rnorm(5) + rnorm(n)
cv <- cv.picasso(X, Y, family = "gaussian", nlambda = 20)
print(cv$lambda.min)
Run the code above in your browser using DataLab