1
拿這個情況下(logistic迴歸經典蟹數據)相同的預測:predict.glmnet()給出了適用於type =「鏈接」和「響應」使用家庭=「二項式」
> library(glmnet)
> X <- read.table("http://www.da.ugent.be/datasets/crab.dat", header=T)[1:10,]
> Y <- factor(ifelse(X$Sa > 0, 1, 0))
> Xnew <- data.frame('W'=20,'Wt'=2000)
> fit.glmnet <- glmnet(x = data.matrix(X[,c('W','Wt')]), y = Y, family = "binomial")
現在我想從Xnew
預測新的價值觀:
按照docs我可以使用predict.glmnet
:
型
需要的預測類型。類型「鏈接」給出了「二項式」,「多項式」,「泊松」或「cox」模型的線性預測變量 ;對於 「高斯」模型,它給出了擬合值。鍵入「響應」給出 爲「二項」或「多項」擬合概率,[...]
所以這是我做的:
> predict.glmnet(object = fit.glmnet, type="response", newx = as.matrix(Xnew))[,1:5]
s0 s1 s2 s3 s4
-0.8472979 -0.9269763 -1.0057390 -1.0836919 -1.1609386
> predict.glmnet(object = fit.glmnet, type="link", newx = as.matrix(Xnew))[,1:5]
s0 s1 s2 s3 s4
-0.8472979 -0.9269763 -1.0057390 -1.0836919 -1.1609386
相同的值都爲link
response
預測,這不是我所期望的。使用predict
似乎給我正確的價值觀:
> predict(object = fit.glmnet, type="response", newx = as.matrix(Xnew))[,1:5]
s0 s1 s2 s3 s4
0.3000000 0.2835386 0.2678146 0.2528080 0.2384968
> predict(object = fit.glmnet, type="link", newx = as.matrix(Xnew))[,1:5]
s0 s1 s2 s3 s4
-0.8472979 -0.9269763 -1.0057390 -1.0836919 -1.1609386
這是一個錯誤,還是我在一個錯誤的方式使用predict.glmnet
?
檢查您的模型的類,然後閱讀'predict.lognet'的代碼。 – Scortchi