使用时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 日创建。