glmnet包使用笔记
最后发布时间:2022-04-11 17:52:32
浏览量:
Logistic Regression
family = "binomial"
library(glmnet)
data(BinomialExample)
x <- BinomialExample$x
y <- BinomialExample$y
fit <- glmnet(x, y, family = "binomial")
predict(fit, newx = x[1:5,], type = "class", s = c(0.05, 0.01))
beta
为不同?下,自变量的系数
> as.matrix(fit$beta)
s0 s1 s2 s3 s4 s5
V1 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V2 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V3 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V4 0 -0.0795432 -0.1525939 -0.21325350 -0.2696943 -0.3229869
V5 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V6 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V7 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
V8 0 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
s
for specifiying the value(s) of ? at which to extract coefficients/predictions.
不同的98个Lambda取值下,的df(自由度),%Dev (percent deviance explained)
> print(fit)
Call: glmnet(x = x, y = y, family = "binomial")
Df %Dev Lambda
1 0 0.00 0.240500
2 1 2.90 0.219100
......
97 30 99.89 0.000032
98 30 99.90 0.000029