【问题标题】:Find the predicted probabilities for logistic/LASSO using caret package in R (using cross validation)使用 R 中的插入符号包查找逻辑/LASSO 的预测概率(使用交叉验证)
【发布时间】:2020-01-25 01:50:18
【问题描述】:

我在 R 中使用 caret 包拟合了一个套索逻辑回归模型。我的代码如下,

require(ISLR)
require(caret)
set.seed(123)
fitControl <- trainControl(method = "cv",number = 5,savePredictions = T,classProbs=TRUE)
mod_fitg <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Volume,
                  data=Smarket[1:100,], method = "glmnet", 
                  trControl = fitControl,
                  tuneGrid=expand.grid(
                    .alpha=1,
                    .lambda=10^seq(-5, 5, length =2)),
                  family="binomial")

当我提取预测值时,它只会显示预测的类(在pred列下),如下所示,

mod_fitg$pred

有没有办法提取预测概率而不是预测类?不知何故,我需要获得基于交叉验证的预测概率。

谢谢

【问题讨论】:

    标签: r cross-validation r-caret


    【解决方案1】:

    我相信您的预测概率在DownUp 列下。该模型为许多观察提供了均匀的机会,并且在这种情况下似乎遵循Up。但是,列表中还有一些变化。 mod_fit$pred 是一个数据框,你可以直接提取值:

    pre_prob <- mod_fitg$pred[3:5]
    pre_prob
    
    #output- keeping index if we care about a certain observation 
        rowIndex      Down        Up
    1          4 0.5000000 0.5000000
    2          8 0.5000000 0.5000000
    

    【讨论】:

      猜你喜欢
      • 2014-07-27
      • 2013-12-26
      • 1970-01-01
      • 2019-11-09
      • 2018-10-22
      • 2015-09-17
      • 1970-01-01
      • 2016-11-20
      相关资源
      最近更新 更多