mlr:提取惩罚的逻辑回归系数

时间:2018-04-17 11:13:11

标签: r coefficients mlr

使用mlr时,拟合模型的参数(根据文档https://mlr-org.github.io/mlr-tutorial/release/html/train/index.html)使用getLearnerModel()访问。然而,通过惩罚逻辑回归,这只是告诉我系数的数量,而不是它们是什么。如何获得系数值?以下是我无法通过getLearnerModel()获取值的示例。

library(mlr); library(titanic); suppressMessages(library(tidyverse))
#> Loading required package: ParamHelpers
data("titanic_train")
data <- titanic_train %>% 
  transmute(age = Age,
            class = as.factor(Pclass),
            survived = as.factor(Survived)) %>% 
  drop_na()
glimpse(data)
#> Observations: 714
#> Variables: 3
#> $ age      <dbl> 22, 38, 26, 35, 35, 54, 2, 27, 14, 4, 58, 20, 39, 14,...
#> $ class    <fct> 3, 1, 3, 1, 3, 1, 3, 3, 2, 3, 1, 3, 3, 3, 2, 3, 3, 2,...
#> $ survived <fct> 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,...
task <- makeClassifTask(data = data, target = "survived")
learner <- makePreprocWrapperCaret("classif.penalized")
#> Loading required package: penalized
#> Loading required package: survival
#> Welcome to penalized. For extended examples, see vignette("penalized").
model <- train(learner, task)
getLearnerModel(model)
#> Model for learner.id=classif.penalized; learner.class=classif.penalized
#> Trained on: task.id = data; obs = 714; features = 2
#> Hyperparameters: trace=FALSE

reprex package(v0.2.0)创建于2018-04-17。

1 个答案:

答案 0 :(得分:1)

您创建了一个包装的学习者。要检索(乘法)嵌套学习器的基础学习器,请使用var2 = (2,7,8) 。对于你的例子

getLearnerModel(model, more.unwrap = TRUE)

应该有用。