| xgb_model | R Documentation |
This function trains a model using the xgboost package. It is highly efficient and natively supports sparse matrices, making it ideal for text data. It automatically handles both binary and multi-class classification problems.
xgb_model(
train_vectorized,
Y,
test_vectorized,
parallel = FALSE,
tune = FALSE,
weights = NULL
)
train_vectorized |
The training feature matrix (e.g., a 'dfm' from quanteda). |
Y |
The response variable for the training set. Should be a factor. |
test_vectorized |
The test feature matrix, which must have the same features as 'train_vectorized'. |
parallel |
Logical |
tune |
Logical |
weights |
A numeric vector of observation weights. Default is NULL |
A list containing four elements:
pred |
A vector of class predictions for the test set. |
probs |
A matrix of predicted probabilities. |
model |
The final, trained 'xgb.Booster' model object. |
best_lambda |
Placeholder (NULL) for pipeline consistency. |
## Not run:
# Create dummy vectorized training and test data
train_matrix <- matrix(runif(100), nrow = 10, ncol = 10)
test_matrix <- matrix(runif(50), nrow = 5, ncol = 10)
# Provide column names (vocabulary) required by xgboost
colnames(train_matrix) <- paste0("word", 1:10)
colnames(test_matrix) <- paste0("word", 1:10)
y_train <- factor(sample(c("P", "N"), 10, replace = TRUE))
# Run xgboost model
model_results <- xgb_model(train_matrix, y_train, test_matrix)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.