在R中使用gbm进行梯度增强,其中分布="bernoulli". [英] Gradient Boosting using gbm in R with distribution = "bernoulli"

查看:90
本文介绍了在R中使用gbm进行梯度增强,其中分布="bernoulli".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中使用 gbm 包,并应用"bernoulli"选项进行分发以构建分类器,并且得到了"nan"和无法预测任何分类结果.但是当我使用"adaboost"时,我没有遇到相同的错误.下面是示例代码,我用虹膜数据集复制了相同的错误.

I am using gbm package in R and applying the 'bernoulli' option for distribution to build a classifier and i get unusual results of 'nan' and i'm unable to predict any classification results. But i do not encounter the same errors when i use 'adaboost'. Below is the sample code, i replicated the same errors with the iris dataset.

## using the iris data for gbm
library(caret)
library(gbm)
data(iris)
Data  <- iris[1:100,-5]
Label <- as.factor(c(rep(0,50), rep(1,50)))

# Split the data into training and testing
inTraining <- createDataPartition(Label, p=0.7, list=FALSE)
training <- Data[inTraining, ]
trainLab <- droplevels(Label[inTraining])
testing <- Data[-inTraining, ]
testLab <- droplevels(Label[-inTraining])

# Model
model_gbm <- gbm.fit(x=training, y= trainLab,
                     distribution = "bernoulli",
                     n.trees = 20, interaction.depth = 1,
                     n.minobsinnode = 10, shrinkage = 0.001,
                     bag.fraction = 0.5, keep.data = TRUE, verbose = TRUE)

## output on the console
Iter      TrainDeviance   ValidDeviance   StepSize   Improve
     1          -nan            -nan     0.0010      -nan
     2           nan            -nan     0.0010       nan
     3          -nan            -nan     0.0010      -nan
     4           nan            -nan     0.0010       nan
     5          -nan            -nan     0.0010      -nan
     6           nan            -nan     0.0010       nan
     7          -nan            -nan     0.0010      -nan
     8           nan            -nan     0.0010       nan
     9          -nan            -nan     0.0010      -nan
    10           nan            -nan     0.0010       nan
    20           nan            -nan     0.0010       nan

请让我知道是否有解决方法可以解决此问题.我使用它的原因是为了尝试加法逻辑回归,请建议R中是否还有其他替代方法可以解决这个问题.

Please let me know if there is a work around to get this working. The reason i am using this is to experiment with Additive Logistic Regression, please suggest if there are any other alternatives in R to go about this.

谢谢.

推荐答案

train.fraction应该小于1以获取ValidDeviance,因为这样我们就可以创建验证数据集.

train.fraction should be <1 to get ValidDeviance, because this way we are creating a validation dataset.

谢谢!

这篇关于在R中使用gbm进行梯度增强,其中分布="bernoulli".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆