Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-validation error #30

Closed
bgreenwell opened this issue Oct 30, 2018 · 2 comments
Closed

Cross-validation error #30

bgreenwell opened this issue Oct 30, 2018 · 2 comments

Comments

@bgreenwell
Copy link
Contributor

bgreenwell commented Oct 30, 2018

# Load required packages
library(gbm)

# Load the data
data(spam, package = "kernlab") 

# Fit a GBM
set.seed(1913)  # for reproducibility
spam_gbm <- gbm(
  ifelse(type == "spam", 1, 0) ~ ., 
  data = spam, 
  distribution = "bernoulli",
  n.trees = 10,
  interaction.depth = 5,
  shrinkage = 0.001,
  bag.fraction = 1,
  train.fraction = 0.7,
  cv.folds = 5,  #<< causes error
  verbose = TRUE
)

# Error in object$var.levels[[i]] : subscript out of bounds
@bgreenwell
Copy link
Contributor Author

bgreenwell commented Jun 24, 2020

Works fine when the response is coded outside of gbm():

spam$type <- ifelse(spam$type == "spam", 1, 0)
spam_gbm <- gbm(
  type ~ ., 
  data = spam, 
  distribution = "bernoulli",
  n.trees = 10,
  interaction.depth = 5,
  shrinkage = 0.001,
  bag.fraction = 1,
  train.fraction = 0.7,
  cv.folds = 5,  
  verbose = TRUE
)

@bgreenwell
Copy link
Contributor Author

bgreenwell commented Jun 24, 2020

Looks like the error occurs in gbmCrossValPredictions(); see below. The commented out line would cause the actual response column to be returned in the prediction data, which predict.gbm() filters):

 # my.data  <- data[flag, !(data.names %in% model$response.name)]
 my.data  <- data[flag, model$var.names]  # patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant