r - gbm 包和分位数回归
问题描述
有人可以指出 gbm 包中分位数分布选项的正确使用吗?这个:
library(datasets)
library(gbm)
library(caret)
set.seed(42)
rm(list = ls())
model <- gbm(Petal.Width ~ Petal.Length
, distribution = list(name = "quantile", alpha = 0.4)
, data = iris
, n.trees = number_of_trees
, interaction.depth = 3
, shrinkage = 0.01,
, n.minobsinnode = 10
)
model
不工作。我得到:
Error in if (!is.element(distribution$name, getAvailableDistributions())) { :
argument is of length zero
Error: object 'model' not found
谢谢!
解决方案
这是 中的一个错误gbm
,如以下 GitHub 问题中所述:#29、#27。它已在此提交中修复。在他们在 CRAN 上获得新版本之前,您可以使用 GitHub 开发版本进行分位数回归:
devtools::install_github("gbm-developers/gbm")
#> Downloading GitHub repo gbm-developers/gbm@master
#> from URL https://api.github.com/repos/gbm-developers/gbm/zipball/master
#> Installing gbm
#> '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore \
#> --quiet CMD INSTALL \
#> '/tmp/Rtmp4acgli/devtools55756447fca5/gbm-developers-gbm-0e07a6b' \
#> --library='/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5' --install-tests
#>
#> Reloading installed gbm
#> Loaded gbm 2.1.4.9000
library(datasets)
library(gbm)
# library(caret) # this package isn't used
set.seed(42)
rm(list = ls())
model <- gbm(Petal.Width ~ Petal.Length
, distribution = list(name = "quantile", alpha = 0.4)
, data = iris
, n.trees = 3 # number_of_trees -- this variable isn't given by OP
, interaction.depth = 3
, shrinkage = 0.01,
, n.minobsinnode = 10
)
model
#> gbm(formula = Petal.Width ~ Petal.Length, distribution = list(name = "quantile",
#> alpha = 0.4), data = iris, n.trees = 3, interaction.depth = 3,
#> n.minobsinnode = 10, shrinkage = 0.01)
#> A gradient boosted model with quantile loss function.
#> 3 iterations were performed.
#> There were 1 predictors of which 1 had non-zero influence.
但不是 CRAN 版本:
install.packages("gbm")
#> Installing package into '/home/duckmayr/R/x86_64-pc-linux-gnu-library/3.5'
#> (as 'lib' is unspecified)
library(datasets)
library(gbm)
#> Loaded gbm 2.1.4
# library(caret) # this package isn't used
set.seed(42)
rm(list = ls())
model <- gbm(Petal.Width ~ Petal.Length
, distribution = list(name = "quantile", alpha = 0.4)
, data = iris
, n.trees = 3 # number_of_trees -- this variable isn't given by OP
, interaction.depth = 3
, shrinkage = 0.01,
, n.minobsinnode = 10
)
#> Error in if (!is.element(distribution$name, getAvailableDistributions())) {: argument is of length zero
model
#> Error in eval(expr, envir, enclos): object 'model' not found
问题是由这段代码引起的:
distribution <- if (missing(distribution)) {
if (missing(distribution)) {
y <- data[, all.vars(formula)[1L], drop = TRUE]
guessDist(y)
} else if (is.character(distribution)) {
distribution <- list(name = distribution)
}
}
您会注意到他们在某些时候忘记了处理用户传递命名列表的情况,就像文档中所说的那样。但是,现在那段代码是固定的:
if (missing(distribution)) {
y <- data[, all.vars(formula)[1L], drop = TRUE]
distribution <- guessDist(y)
}
if (is.character(distribution)) {
distribution <- list(name = distribution)
}
这样如果distribution
已经是一个列表,它现在就不会受到干扰。
推荐阅读
- python - 当没有更多要附加到列表的项目时,如何打破循环?
- python-3.x - 他们是如何提出计算 2 个数的模块的方程式“a%b = ab*(a//b)”
- apache - 使用别名和反向代理时 Apache 2.4 压缩不起作用
- bash - 您如何在 mac 上找到用于键盘绑定的 bash 的终端键代码?
- c# - Unity实例化预制件并获取组件
- git - 为什么我会在 Git 终端中名为 HTML Tid Bits.docx 的文件前面看到这个 ~$ML?
- f# - 如何从 F# 调用 Q# 操作
- java - 如何修复 if 和 else if 语句没有选择正确的语句
- javascript - 从嵌套函数内部的forEach循环内部退出主函数
- mule - 在 Mule 4 中使用 Groovy 脚本调用流