Description Usage Arguments Value Author(s) References Examples
A fitting function with cross-validation for both α and λ. See aglm-package for more details on α and λ.
1 2 3 4 5 6 7 8 9 |
x |
A design matrix. See aglm for more details. |
y |
A response variable. |
alpha |
A numeric vector representing α values to be examined in cross-validation. |
nfolds |
An integer value representing the number of folds. |
foldid |
An integer vector with the same length as observations.
Each element should take a value from 1 to |
parallel.alpha |
(not used yet) |
... |
Other arguments are passed directly to |
An object storing fitted models and information of cross-validation. See CVA_AccurateGLM-class for more details.
Kenji Kondo,
Kazuhisa Takahashi and Hikari Banno (worked on L-Variable related features)
Suguru Fujita, Toyoto Tanaka, Kenji Kondo and Hirokazu Iwasawa. (2020)
AGLM: A Hybrid Modeling Method of GLM and Data Science Techniques,
https://www.institutdesactuaires.com/global/gene/link.php?doc_id=16273&fg=1
Actuarial Colloquium Paris 2020
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #################### Cross-validation for alpha and lambda ####################
library(aglm)
library(faraway)
## Read data
xy <- nes96
## Split data into train and test
n <- nrow(xy) # Sample size.
set.seed(2018) # For reproducibility.
test.id <- sample(n, round(n/5)) # ID numbders for test data.
test <- xy[test.id,] # test is the data.frame for testing.
train <- xy[-test.id,] # train is the data.frame for training.
x <- train[, c("popul", "TVnews", "selfLR", "ClinLR", "DoleLR", "PID", "age", "educ", "income")]
y <- train$vote
newx <- test[, c("popul", "TVnews", "selfLR", "ClinLR", "DoleLR", "PID", "age", "educ", "income")]
# NOTE: Codes bellow will take considerable time, so run it when you have time.
## Fit the model
cva_result <- cva.aglm(x, y, family="binomial")
alpha <- cva_result@alpha.min
lambda <- cva_result@lambda.min
mod_idx <- cva_result@alpha.min.index
model <- cva_result@models_list[[mod_idx]]
## Make the confusion matrix
y_true <- test$vote
y_pred <- levels(y_true)[as.integer(predict(model, newx, s=lambda, type="class"))]
cat(sprintf("Confusion matrix for alpha=%.5f and lambda=%.5f:\n", alpha, lambda))
print(table(y_true, y_pred))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.