'XGBoost object 'trainD' not found

I was running this code on RStudio

param <- list(colsample_bytree = 1,
              subsample = .6,
              booster = "gbtree",
              max_depth = 8,
              eta = 0.05,
              min_child_weight = 2,
              eval_metric = "rmse",
              objective="reg:linear",
              gamma = 0.01)

bstSparse <-
  xgb.train(params = param,
            data = trainD,
            nrounds = 400,
            watchlist = list(train = trainD),
            verbose = TRUE,
            print_every_n = 50,
            nthread = 2)

and I keep getting this error message. I was wondering if I'm missing a package;

Error in xgb.train(params = param, data = trainD, nrounds = 400, watchlist = list(train = trainD),  : 
  object 'trainD' not found

The next part of the code is

prediction <- predict(bstSparse, testD)
prediction <- as.data.frame(as.matrix(prediction))
colnames(prediction) <- "prediction"

model_output <- cbind(test, prediction)
submission <- data.frame(Id = test$Id, SalePrice = model_output$prediction)
submission$SalePrice <- exp(submission$SalePrice) + 1

head(submission)

but I can't get rid of the error code to proceed. The code excerpt is from here btw https://rstudio-pubs-static.s3.amazonaws.com/349700_be0afbbec67a4b48a56878f32c28f710.html



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source