1

使用时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 包(v0.2.0)于 2018 年 4 月 17 日创建。

4

1 回答 1

2

您已经创建了一个封装的学习器。要检索(乘)嵌套学习器的基础学习器,请使用getLearnerModel(model, more.unwrap = TRUE). 对于你的例子

coef(getLearnerModel(model, more.unwrap = TRUE))

应该管用。

于 2018-04-18T09:11:28.470 回答