This package provides functions to generate ensembles of generalized linear models using competing proximal gradients.
You can install the stable version on R CRAN.
install.packages("CPGLIB", dependencies = TRUE)
You can install the development version from GitHub
library(devtools)
::install_github("AnthonyChristidis/CPGLIB") devtools
# Required Libraries
library(mvnfast)
# Sigmoid function
<- function(t){
sigmoid return(exp(t)/(1+exp(t)))
}
# Data simulation
set.seed(1)
<- 50
n <- 2000
N <- 300
p <- c(abs(runif(p, 0, 1/2))*(-1)^rbinom(p, 1, 0.3))
beta.active # Parameters
<- 150
p.active <- c(beta.active[1:p.active], rep(0, p-p.active))
beta <- matrix(0, p, p)
Sigma 1:p.active, 1:p.active] <- 0.5
Sigma[diag(Sigma) <- 1
# Train data
<- rmvn(n, mu = rep(0, p), sigma = Sigma)
x.train <- sigmoid(x.train %*% beta)
prob.train <- rbinom(n, 1, prob.train)
y.train
# Test data
<- rmvn(N, mu = rep(0, p), sigma = Sigma)
x.test <- sigmoid(x.test %*% beta + offset)
prob.test <- rbinom(N, 1, prob.test)
y.test mean(y.test)
<- y.test==0
sp.sen.par
# CPGLIB - CV (Multiple Groups)
<- cv.cpg(x.train, y.train,
cpg.out type="Logistic",
G=5, include_intercept=TRUE,
alpha_s=3/4, alpha_d=4/4,
n_lambda_sparsity=100, n_lambda_diversity=100,
tolerance=1e-3, max_iter=1e3,
n_folds=5,
n_threads=1)
# Coefficients
<- coef(cpg.out, ensemble_average=TRUE)
cpg.coef
# Plot of predicted probabilities
<- predict(cpg.out, x.test, groups=1:cpg.out$G, class_type="prob", ensemble_type="Model-Avg")
cpg.prob plot(prob.test, cpg.prob, pch=20)
abline(h=0.5,v=0.5)
# Misclassification rate
<- predict(cpg.out, x.test, groups=1:10, class_type="class", ensemble_type="Model-Avg")
cpg.class mean(abs(y.test-cpg.class))
This package is free and open source software, licensed under GPL (>= 2).