Learn R Programming

picasso (version 2.0.1)

cv.picasso: Cross-Validation for picasso

Description

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.

Usage

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", ...)

Value

cv.picasso returns an object of class "cv.picasso" with components:

lambda

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.

cvm

Mean cross-validated error for each lambda.

cvsd

Standard error of the mean cross-validated error.

cvup, cvlo

Upper and lower error-bar bounds.

nzero

Number of nonzero coefficients at each lambda. For multinomial models this is the total across all classes.

lambda.min

Lambda that minimises cvm.

lambda.1se

Largest lambda within one standard error of the minimum.

name

Name of the loss measure used.

foldid

Fold assignment used for each observation.

family

Model family.

fast.mode

Logical precision preset used for all fits.

prec

Effective convergence tolerance used for all fits.

picasso.fit

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.

Arguments

X

Numeric design matrix, \(n \times d\).

Y

Response vector. A one-column Gaussian response matrix is accepted for compatibility.

...

Additional arguments passed to picasso.

nfolds

Number of cross-validation folds. Default is 10.

foldid

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.)

type.measure

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.

fast.mode

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.

x

A "cv.picasso" object.

object

A "cv.picasso" object.

s

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.

sign.lambda

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.

newdata

Matrix of new observations for prediction.

type

Prediction type; passed to the underlying predict method.

Author

Jason Ge, Xingguo Li, Haoming Jiang, Mengdi Wang, Tong Zhang, Han Liu and Tuo Zhao
Maintainer: Tuo Zhao <tourzhao@gatech.edu>

Details

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.

See Also

picasso

Examples

Run this code
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