4

考虑下面的简短 R 脚本。似乎这boost.hitters$train.error与训练集的原始残差或平方误差都不匹配。

我根本找不到文档train.error,所以我想知道是否有人知道train.error这里真正代表什么以及它是如何计算的?

library(ISLR)
library(gbm)

set.seed(1)

Hitters=na.omit(Hitters)
Hitters$Salary = log(Hitters$Salary)

boost.hitters=gbm(Salary~.,data=Hitters, n.trees=1000,interaction.depth=4, shrinkage= 0.01)
yhat.boost=predict(boost.hitters,newdata=Hitters,n.trees=1000)

mean(boost.hitters$train.error^2)
mean(boost.hitters$train.error)

mean((yhat.boost-Hitters$Salary)^2)

输出:

[1] 0.03704581
[1] 0.1519719
[1] 0.07148612
4

1 回答 1

6

我问了我大学的一位教授。

显然train.error表示每棵树添加后的训练误差(即 MSE)。因此我计算的误差等于最后一棵树的训练误差,所以在我的例子中:

mean((yhat.boost-Hitters$Salary)^2) == boost.hitters$train.error[1000] 
于 2013-11-19T23:53:49.320 回答