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")
# use 30 percent for validation
# Set early stopping parameter
learner = lrn("classif.xgboost",
nrounds = 100,
early_stopping_rounds = 10,
validate = 0.3
)
# Train learner with early stopping
learner$train(task)
# Inspect optimal nrounds and validation performance
learner$internal_tuned_values
learner$internal_valid_scores
}
Run the code above in your browser using DataLab