View source: R/ordinal_reg-glmnetcr.R
| predict_glmnetcr_wrapper | R Documentation |
glmnetcrSelect predictions at a specific penalty value or a vector of penalty values. For penalties between path values, linearly interpolate between the probability matrices at the neighboring steps. For penalties outside the path range, use the path endpoints.
predict_glmnetcr_wrapper(
object,
newx,
type,
lambda,
criteria = c("bic", "aic")
)
multi_predict_glmnetcr_wrapper(object, newx, type, lambda)
## S3 method for class ''_glmnetcr''
predict(
object,
new_data,
type = NULL,
opts = list(),
penalty = NULL,
multi = FALSE,
...
)
## S3 method for class ''_glmnetcr''
predict_class(object, new_data, ...)
## S3 method for class ''_glmnetcr''
predict_classprob(object, new_data, ...)
## S3 method for class ''_glmnetcr''
multi_predict(
object,
new_data,
type = NULL,
opts = list(),
penalty = NULL,
...
)
object |
A |
newx |
A predictor matrix. |
type |
Either |
lambda |
A penalty value or vector at which to predict. If |
criteria |
The criterion by which to select |
penalty |
A numeric vector of penalty values. Overrides the default
penalty. If |
predict_glmnetcr_wrapper() returns a character vector of class
predictions or a matrix of class probabilities.
multi_predict_glmnetcr_wrapper() returns a numeric array with one slice
per penalty value for class probabilities, or a character matrix with one
column per penalty value for class predictions.
Both outputs mimic those of glmnetcr::predict.glmnetcr().
house_data <-
MASS::housing[rep(seq(nrow(MASS::housing)), MASS::housing$Freq), -5]
house_matrix <- model.matrix(
Sat ~ Type + Infl + Cont + 0,
data = house_data,
contrasts.arg = lapply(house_data[, 2:4], contrasts, contrasts = FALSE)
)
pen_vec <- 10 ^ seq(-1, -2, -.25)
fit <- glmnetcr::glmnetcr(
house_matrix, y = house_data$Sat,
lambda = pen_vec
)
# predictions (may disagree if `lambda` is not on the path `fit$lambda`)
set.seed(34091)
house_submatrix <- house_matrix[sample(nrow(house_matrix), 6), ]
# single, probability
predict(
fit,
newx = house_submatrix
)$probs[, , which.min(abs(fit$lambda - .02))]
predict_glmnetcr_wrapper(
fit,
newx = house_submatrix,
type = "prob",
lambda = .02
)
# single, class
predict(
fit,
newx = house_submatrix
)$class[, which.min(abs(fit$lambda - .02))]
predict_glmnetcr_wrapper(
fit,
newx = house_submatrix,
type = "class",
lambda = .02
)
# multiple, probabilities
predict(
fit,
newx = house_submatrix
)$probs
multi_predict_glmnetcr_wrapper(
fit,
newx = house_submatrix,
type = "prob",
lambda = c(.2, .02, .002)
)
# multiple, class
predict(
fit,
newx = house_submatrix
)$class
multi_predict_glmnetcr_wrapper(
fit,
newx = house_submatrix,
type = "class",
lambda = c(.2, .02, .002)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.