【问题标题】:calculate r square (Multiple determination coefficient) using GBM in R使用 R 中的 GBM 计算 r 平方(多重决定系数)
【发布时间】:2021-04-29 07:03:45
【问题描述】:

我执行 GBM 模型。 数据样本

a=structure(list(yield = c(1842L, 2147L, 2444L, 3850L, 1866L, 2897L, 
1783L, 2434L, 2650L, 2863L), time.diff = c(122, 186, 177, 168, 
162, 186, 161, 125, 187, 185), Biomass = c(18400L, 6400L, 8620L, 
12800L, 5400L, 10400L, 6000L, 8800L, 9080L, 60000L)), class = "data.frame", row.names = c(NA, 
-10L))

我的代码

indexes = createDataPartition(a$yield, p = .7, list = F)
train = a[indexes, ]
test = a[-indexes, ]

write.csv(test,"test.csv")

ames_train <- train
ames_test  <- test

str(ames_train)

# train GBM model
gbm.fit <- gbm(
  formula = yield ~ .,
  distribution = "gaussian",
  data = ames_train,
  n.trees = 10000,
  interaction.depth = 1,
  shrinkage = 0.001,
  cv.folds = 5,
  n.cores = NULL, # will use all cores by default
  verbose = FALSE
)  


# print results
print(gbm.fit)


# get MSE and compute RMSE
sqrt(min(gbm.fit$cv.error))

这里表示MSE和RMSE 我如何计算这个模型的 r 平方(多重决定系数)?

【问题讨论】:

    标签: r gbm


    【解决方案1】:

    这样你就可以得到 r2 和通过交叉验证获得的预测,这是真实的预测。

    r <- as.numeric(gbm.fit$cv.statistics[3])
    
    rsq = round(r^2,2)
    

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 2017-04-15
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多