Skip to content

Instantly share code, notes, and snippets.

@thomasjungblut
Last active November 14, 2019 04:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasjungblut/e60217c5b7609e4dfef3 to your computer and use it in GitHub Desktop.
Save thomasjungblut/e60217c5b7609e4dfef3 to your computer and use it in GitHub Desktop.
XGBoost Validation and Early Stopping in R
train <- read.csv("train.csv")
bound <- floor(nrow(train) * 0.9)
train <- train[sample(nrow(train)), ]
df.train <- train[1:bound, ]
df.validation <- train[(bound+1):nrow(train), ]
train.y <- df.train$TARGET
validation.y <- df.validation$TARGET
dtrain <- xgb.DMatrix(data=df.train, label=train.y)
dvalidation <- xgb.DMatrix(data=df.validation, label=validation.y)
watchlist <- list(validation=dvalidation, train=dtrain)
param <- list(
objective = "binary:logistic",
eta = 0.3,
max_depth = 8
)
clf <- xgb.train(
params = param,
data = dtrain,
nrounds = 500,
watchlist = watchlist,
maximize = FALSE,
early.stop.round = 20
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment