Ant*_*ony 1 statistics r classification data-analysis tidymodels
我使用 tidymodels 框架拟合多项式逻辑回归模型来预测鸢尾花数据集中的物种。
library(tidymodels)
iris.lr = multinom_reg(
mode="classification",
penalty=NULL,
mixture=NULL
) %>%
set_engine("glmnet")
iris.fit = iris.lr %>%
fit(Species ~. , data = iris)
Run Code Online (Sandbox Code Playgroud)
然后我想查看模型的系数并写出公式。我的理解是我应该从 iris.fit 获取这个。
iris.fit 的输出有一个 100 行表,其中包含 Df、%Dev 、Lambda。iris 数据集只有 4 个预测变量。如何将此输出转换为系数?
您可以使用该函数获取数据框中的所有系数(针对每个测试的 lambda)tidy()。
library(tidymodels)\n#> \xe2\x94\x80\xe2\x94\x80 Attaching packages \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 tidymodels 0.1.0 \xe2\x94\x80\xe2\x94\x80\n#> \xe2\x9c\x93 broom 0.5.6 \xe2\x9c\x93 recipes 0.1.12\n#> \xe2\x9c\x93 dials 0.0.6 \xe2\x9c\x93 rsample 0.0.6 \n#> \xe2\x9c\x93 dplyr 0.8.5 \xe2\x9c\x93 tibble 3.0.1 \n#> \xe2\x9c\x93 ggplot2 3.3.0 \xe2\x9c\x93 tune 0.1.0 \n#> \xe2\x9c\x93 infer 0.5.1 \xe2\x9c\x93 workflows 0.1.1 \n#> \xe2\x9c\x93 parsnip 0.1.1 \xe2\x9c\x93 yardstick 0.0.6 \n#> \xe2\x9c\x93 purrr 0.3.4\n#> \xe2\x94\x80\xe2\x94\x80 Conflicts \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 tidymodels_conflicts() \xe2\x94\x80\xe2\x94\x80\n#> x purrr::discard() masks scales::discard()\n#> x dplyr::filter() masks stats::filter()\n#> x dplyr::lag() masks stats::lag()\n#> x ggplot2::margin() masks dials::margin()\n#> x recipes::step() masks stats::step()\n\niris_lr <- multinom_reg(\n mode = "classification",\n penalty = NULL,\n mixture = NULL\n) %>%\n set_engine("glmnet")\n\niris_fit = iris_lr %>%\n fit(Species ~ . , data = iris)\n\nlibrary(broom)\n\ntidy(iris_fit)\n#> # A tibble: 839 x 6\n#> class term step estimate lambda dev.ratio\n#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>\n#> 1 setosa "" 1 6.41e-16 0.435 -1.21e-15\n#> 2 versicolor "" 1 -1.62e-15 0.435 -1.21e-15\n#> 3 virginica "" 1 9.81e-16 0.435 -1.21e-15\n#> 4 setosa "" 2 2.44e- 1 0.396 6.56e- 2\n#> 5 setosa "Petal.Length" 2 -9.85e- 2 0.396 6.56e- 2\n#> 6 versicolor "" 2 -1.22e- 1 0.396 6.56e- 2\n#> 7 virginica "" 2 -1.22e- 1 0.396 6.56e- 2\n#> 8 setosa "" 3 4.62e- 1 0.361 1.20e- 1\n#> 9 setosa "Petal.Length" 3 -1.89e- 1 0.361 1.20e- 1\n#> 10 versicolor "" 3 -2.31e- 1 0.361 1.20e- 1\n#> # \xe2\x80\xa6 with 829 more rows\nRun Code Online (Sandbox Code Playgroud)\n\n由reprex 包(v0.3.0)于 2020-05-14 创建
\n