Description Usage Arguments Value Examples
Rcpp-based objective function for L1- or L2-regularized logistic regression
1 | objective_cpp(beta0, beta, x, y, lambda, alpha = 0)
|
beta0 |
intercept |
beta |
a feature matrix |
x |
observations |
y |
response |
lambda |
penalty |
alpha |
elasticnet mixing parameter |
Objective function value.
1 2 3 4 5 6 7 8 9 | if (requireNamespace("glmnet")) {
x <- matrix(rnorm(100*20), 100, 20)
y <- sample(1:2, 100, replace = TRUE)
fit <- glmnet::cv.glmnet(x, y, family = "binomial")
lambda <- fit$lambda.1se
beta0 <- coef(fit, lambda)[1]
beta <- coef(fit, lambda)[-1]
objective_cpp(beta0, beta, t(x), y, lambda, alpha = 1)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.