【问题标题】:Predicting counts using mlr使用 mlr 预测计数
【发布时间】:2018-10-31 15:01:48
【问题描述】:

我正在使用学习器regr.gbm 来预测计数。在mlr 之外,直接使用gbm 包,我使用distribution = "poisson" 和predict.gbm,使用type = "response",返回原始比例的预测,但是我注意到当我使用mlr 执行此操作时,预测似乎在对数尺度上:

     truth    response
913      4  0.67348708
914      1  0.28413256
915      3  0.41871237
916      1  0.13027792
2101     1 -0.02092168
2102     2  0.23394970

但是,“真相”不在对数范围内,因此我担心mlr 中的超参数调整例程将无法正常工作。作为比较,这是我使用distribution = "gaussian" 得到的输出。

     truth response
913      4 2.028177
914      1 1.334658
915      3 1.552846
916      1 1.153072
2101     1 1.006362
2102     2 1.281811

处理这个问题的最佳方法是什么?

【问题讨论】:

  • mlr 不对 gbm 返回的预测进行任何处理——您能否发布一个完整的示例来说明问题?

标签: r machine-learning mlr


【解决方案1】:

发生这种情况是因为gbm 默认情况下会根据链接函数规模进行预测(log 对应于distribution = "poisson")。这由gbm::predict.gbm 的type 参数控制(参见该函数的帮助页面)。不幸的是,mlr 默认不提供更改此参数(mlr bugtracker 中的it was reported)。目前的解决方法是手动添加此参数:

lrn <- makeLearner("regr.gbm", distribution = "poisson")
lrn$par.set <- c(lrn$par.set,
  makeParamSet(
    makeDiscreteLearnerParam("type", c("link", "response"),
      default = "link", when = "predict", tunable = FALSE)))
lrn <- setHyperPars(lrn, type = "response")

# show that it works:
counttask <- makeRegrTask("counttask", getTaskData(pid.task),
  target = "pregnant")
pred <- predict(train(lrn, counttask), counttask)
pred

请注意,在调整计数数据的参数时,默认回归度量(均方误差)可能会过分强调对具有大计数值的数据点的拟合。预测“10”而不是“1”的平方误差与预测“1010”而不是“1001”的误差相同,但根据您的目标,您可能希望在此示例中更重视第一个错误。

一种可能的解决方案是使用(标准化)平均泊松对数似然作为度量:

poisllmeasure = makeMeasure(
  id = "poissonllnorm",
  minimize = FALSE,
  best = 0,
  worst = -Inf,
  properties = "regr",
  name = "Mean Poisson Log Likelihood",
  note = "For count data. Normalized to 0 for perfect fit.",
  fun = function(task, model, pred, feats, extra.args) {
    mean(dpois(pred$data$truth, pred$data$response, log = TRUE) -
      dpois(pred$data$truth, pred$data$truth, log = TRUE))
})
# example
performance(pred, poisllmeasure)

此度量可用于调整,方法是将其提供给tuneParams() 中的measures 参数。 (请注意,您必须在列表中提供它:tuneParams(... measures = list(poisllmeasure) ...))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2022-10-10
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    相关资源
    最近更新 更多