gpt4 book ai didi

r - Tidymodels 逻辑回归获取系数和标准误差

转载 作者:行者123 更新时间:2023-12-04 02:33:41 25 4
gpt4 key购买 nike

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

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

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


glm.fit$fit$coefficients

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

最佳答案

你可以试试:

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

关于r - Tidymodels 逻辑回归获取系数和标准误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62865099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com