if (FALSE) {
if (requireNamespace("xgboost", quietly = TRUE)) {
# Define the Learner and set parameter values
learner = lrn("classif.xgboost")
print(learner)
# Define a Task
task = tsk("sonar")
# Create train and test set
ids = partition(task)
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
# print the model
print(learner$model)
# importance method
if("importance" %in% learner$properties) print(learner$importance)
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
}
}
if (FALSE) {
# Train learner with early stopping on spam data set
task = tsk("spam")
# Split task into training and test set
split = partition(task, ratio = 0.8)
task$set_row_roles(split$test, "test")
# Set early stopping parameter
learner = lrn("classif.xgboost",
nrounds = 100,
early_stopping_rounds = 10,
early_stopping_set = "test"
)
# Train learner with early stopping
learner$train(task)
}
Run the code above in your browser using DataLab