【问题标题】:Tidymodels Logistic Regression getting coefficients and standard errorsTidymodels Logistic Regression 获取系数和标准误差
【发布时间】:2020-07-12 18:37:25
【问题描述】:

有没有办法在 tidy 模型中获取逻辑回归的标准误和 p 值?

我可以通过下面的代码获得系数..但我想计算每个特征的优势比,我还需要标准误差..

glm.fit <- 
  logistic_reg(mode = "classification") %>%
  set_engine(engine = "glm") %>% 
  fit(Species ~ ., data = iris)


glm.fit$fit$coefficients

通常你可以通过在 glm 对象上调用 summary() 来做到这一点,但我在这里尝试使用 tidymodels。

【问题讨论】:

    标签: r machine-learning tidymodels


    【解决方案1】:

    你可以试试:

    library(broom)
    library(tidymodels)
    
    glm.fit <- 
      logistic_reg(mode = "classification") %>%
      set_engine(engine = "glm") %>% 
      fit(Species ~ ., data = iris)
    
    tidy(glm.fit)
    
    # A tibble: 5 x 5
      term         estimate std.error  statistic p.value
      <chr>           <dbl>     <dbl>      <dbl>   <dbl>
    1 (Intercept)     16.9    457457.  0.0000370    1.00
    2 Sepal.Length   -11.8    130504. -0.0000901    1.00
    3 Sepal.Width     -7.84    59415. -0.000132     1.00
    4 Petal.Length    20.1    107725.  0.000186     1.00
    5 Petal.Width     21.6    154351.  0.000140     1.00
    

    【讨论】:

      猜你喜欢
      • 2015-10-12
      • 2018-07-07
      • 2019-09-13
      • 1970-01-01
      • 2014-02-27
      • 2021-04-30
      • 1970-01-01
      • 2019-05-25
      • 2017-10-08
      相关资源
      最近更新 更多