我如何抵消R中的GBM模型中的暴露



我试图将梯度提升机(GBM)适合保险索赔。观察值的暴露不平等,因此我试图使用等于暴露日志的偏移。我尝试了两种不同的方法:

  1. 将偏移项放在公式中。这导致了每次迭代的火车和验证偏差的nan

  2. 使用gbm功能中的offset参数。此参数在gbm.more下列出。这导致一条错误消息,即有一个未使用的参数。

我无法共享公司的数据,但是我使用Mass软件包中的保险数据表重现了问题。请参阅下面的代码和输出。

library(MASS)
library(gbm)
data(Insurance)
# Try using offset in the formula.
fm1 = formula(Claims ~ District + Group + Age + offset(log(Holders)))
fitgbm1 = gbm(fm1, distribution = "poisson",
              data = Insurance,
              n.trees = 10,
              shrinkage = 0.1,
              verbose = TRUE)
# Try using offset in the gbm statement.
fm2 = formula(Claims ~ District + Group + Age)
offset2 = log(Insurance$Holders)
fitgbm2 = gbm(fm2, distribution = "poisson",
              data = Insurance,
              n.trees = 10,
              shrinkage = 0.1,
              offset = offset2,
              verbose = TRUE)

然后输出:

> source('D:/Rprojects/auto_tutorial/rcode/example_gbm.R')
Iter   TrainDeviance   ValidDeviance   StepSize   Improve
     1     -347.8959             nan     0.1000    0.0904
     2     -348.2181             nan     0.1000    0.0814
     3     -348.3845             nan     0.1000    0.0616
     4     -348.5424             nan     0.1000    0.0333
     5     -348.6732             nan     0.1000    0.0850
     6     -348.7744             nan     0.1000    0.0610
     7     -348.8795             nan     0.1000    0.0633
     8     -348.9132             nan     0.1000   -0.0109
     9     -348.9200             nan     0.1000   -0.0212
    10     -349.0271             nan     0.1000    0.0267
Error in gbm(fm2, distribution = "poisson", data = Insurance, n.trees = 10,  : 
  unused argument (offset = offset2)

我的问题是我在做什么错?另外,还有另一种方法吗?我注意到gbm功能中的权重参数。我应该使用吗?

如果您指定培训分数小于1。默认值为1,这意味着没有验证集。

library(MASS)
library(gbm)
data(Insurance)
# Try using offset in the formula.
fm1 = formula(Claims ~ District + Group + Age + offset(log(Holders)))
fitgbm1 = gbm(fm1, distribution = "poisson",
              data = Insurance,
              n.trees = 10,
              shrinkage = 0.1,
              verbose = TRUE,
              train.fraction = .75)

导致

Iter   TrainDeviance   ValidDeviance   StepSize   Improve
     1     -428.8293       -105.1735     0.1000    0.0888
     2     -429.0869       -105.3063     0.1000    0.0708
     3     -429.1805       -105.3941     0.1000    0.0486
     4     -429.3414       -105.4816     0.1000    0.0933
     5     -429.4934       -105.5432     0.1000    0.0566
     6     -429.6714       -105.5188     0.1000    0.1212
     7     -429.8470       -105.5200     0.1000    0.0833
     8     -429.9655       -105.6073     0.1000    0.0482
     9     -430.1367       -105.6003     0.1000    0.0473
    10     -430.2462       -105.6100     0.1000    0.0487

最新更新