View source: R/AutoXGBoostMultiClass.R
AutoXGBoostMultiClass | R Documentation |
AutoXGBoostMultiClass is an automated XGBoost modeling framework with grid-tuning and model evaluation that runs a variety of steps. First, a stratified sampling (by the target variable) is done to create train and validation sets. Then, the function will run a random grid tune over N number of models and find which model is the best (a default model is always included in that set). Once the model is identified and built, several other outputs are generated: validation data with predictions, evaluation metrics, variable importance, and column names used in model fitting.
AutoXGBoostMultiClass(
OutputSelection = c("Importances", "EvalMetrics", "Score_TrainData"),
data = NULL,
TrainOnFull = FALSE,
ValidationData = NULL,
TestData = NULL,
TargetColumnName = NULL,
FeatureColNames = NULL,
WeightsColumnName = NULL,
IDcols = NULL,
model_path = NULL,
metadata_path = NULL,
ModelID = "FirstModel",
LossFunction = "multi:softprob",
EncodingMethod = "credibility",
ReturnFactorLevels = TRUE,
ReturnModelObjects = TRUE,
SaveModelObjects = FALSE,
Verbose = 0L,
DebugMode = FALSE,
NumOfParDepPlots = 3L,
NThreads = parallel::detectCores(),
eval_metric = "merror",
grid_eval_metric = "accuracy",
TreeMethod = "hist",
GridTune = FALSE,
BaselineComparison = "default",
MaxModelsInGrid = 10L,
MaxRunsWithoutNewWinner = 20L,
MaxRunMinutes = 24L * 60L,
PassInGrid = NULL,
early_stopping_rounds = 100L,
Trees = 50L,
num_parallel_tree = 1,
eta = NULL,
max_depth = NULL,
min_child_weight = NULL,
subsample = NULL,
colsample_bytree = NULL,
alpha = 0,
lambda = 1
)
OutputSelection |
You can select what type of output you want returned. Choose from c("Importances", "EvalPlots", "EvalMetrics", "Score_TrainData") |
data |
This is your data set for training and testing your model |
TrainOnFull |
Set to TRUE to train on full data |
ValidationData |
This is your holdout data set used in modeling either refine your hyperparameters. |
TestData |
This is your holdout data set. Catboost using both training and validation data in the training process so you should evaluate out of sample performance with this data set. |
TargetColumnName |
Either supply the target column name OR the column number where the target is located (but not mixed types). Note that the target column needs to be a 0 | 1 numeric variable. |
FeatureColNames |
Either supply the feature column names OR the column number where the target is located (but not mixed types) |
WeightsColumnName |
Supply a column name for your weights column. Leave NULL otherwise |
IDcols |
A vector of column names or column numbers to keep in your data but not include in the modeling. |
model_path |
A character string of your path file to where you want your output saved |
metadata_path |
A character string of your path file to where you want your model evaluation output saved. If left NULL, all output will be saved to model_path. |
ModelID |
A character string to name your model and output |
LossFunction |
Use 'multi:sofprob', I set it up to return the class label and the individual probabilities, just like catboost. Doesn't come like that off the shelf |
EncodingMethod |
Choose from 'binary', 'm_estimator', 'credibility', 'woe', 'target_encoding', 'poly_encode', 'backward_difference', 'helmert' |
ReturnFactorLevels |
TRUE or FALSE. Set to FALSE to not return factor levels. |
ReturnModelObjects |
Set to TRUE to output all modeling objects (E.g. plots and evaluation metrics) |
SaveModelObjects |
Set to TRUE to return all modeling objects to your environment |
Verbose |
Set to 0 if you want to suppress model evaluation updates in training |
DebugMode |
Set to TRUE to get a print out of the steps taken internally |
NumOfParDepPlots |
Tell the function the number of partial dependence calibration plots you want to create. |
NThreads |
Set the maximum number of threads you'd like to dedicate to the model run. E.g. 8 |
eval_metric |
This is the metric used to identify best grid tuned model. Choose from 'merror' or 'mlogloss' |
grid_eval_metric |
"accuracy", "logloss", "microauc" |
TreeMethod |
Choose from "hist", "gpu_hist" |
GridTune |
Set to TRUE to run a grid tuning procedure |
BaselineComparison |
Set to either "default" or "best". Default is to compare each successive model build to the baseline model using max trees (from function args). Best makes the comparison to the current best model. |
MaxModelsInGrid |
Number of models to test from grid options. |
MaxRunsWithoutNewWinner |
A number |
MaxRunMinutes |
In minutes |
PassInGrid |
Default is NULL. Provide a data.table of grid options from a previous run. |
early_stopping_rounds |
= 10L |
Trees |
Bandit grid partitioned. Supply a single value for non-grid tuning cases. Otherwise, supply a vector for the trees numbers you want to test. For running grid tuning, a NULL value supplied will mean these values are tested seq(1000L, 10000L, 1000L) |
num_parallel_tree |
= 1. If setting greater than 1, set colsample_bytree < 1, subsample < 1 and round = 1 |
eta |
Bandit grid partitioned. Supply a single value for non-grid tuning cases. Otherwise, supply a vector for the LearningRate values to test. For running grid tuning, a NULL value supplied will mean these values are tested c(0.01,0.02,0.03,0.04) |
max_depth |
Bandit grid partitioned. Number, or vector for depth to test. For running grid tuning, a NULL value supplied will mean these values are tested seq(4L, 16L, 2L) |
min_child_weight |
Number, or vector for min_child_weight to test. For running grid tuning, a NULL value supplied will mean these values are tested seq(1.0, 10.0, 1.0) |
subsample |
Number, or vector for subsample to test. For running grid tuning, a NULL value supplied will mean these values are tested seq(0.55, 1.0, 0.05) |
colsample_bytree |
Number, or vector for colsample_bytree to test. For running grid tuning, a NULL value supplied will mean these values are tested seq(0.55, 1.0, 0.05) |
alpha |
0. L1 Reg. |
lambda |
1. L2 Reg. |
Saves to file and returned in list: VariableImportance.csv, Model, ValidationData.csv, EvaluationMetrics.csv, GridCollect, GridList, and TargetLevels
Adrian Antico
Other Automated Supervised Learning - Multiclass Classification:
AutoCatBoostMultiClass()
,
AutoH2oDRFMultiClass()
,
AutoH2oGAMMultiClass()
,
AutoH2oGBMMultiClass()
,
AutoH2oGLMMultiClass()
,
AutoH2oMLMultiClass()
## Not run:
data <- AutoQuant::FakeDataGenerator(
Correlation = 0.85,
N = 1000L,
ID = 2L,
ZIP = 0L,
AddDate = FALSE,
Classification = FALSE,
MultiClass = TRUE)
# Run function
TestModel <- AutoQuant::AutoXGBoostMultiClass(
# GPU or CPU
TreeMethod = "hist",
NThreads = parallel::detectCores(),
# Metadata args
OutputSelection = c("Importances", "EvalPlots", "EvalMetrics", "PDFs", "Score_TrainData"),
model_path = normalizePath("./"),
metadata_path = normalizePath("./"),
ModelID = "Test_Model_1",
EncodingMethod = "binary",
ReturnFactorLevels = TRUE,
ReturnModelObjects = TRUE,
SaveModelObjects = FALSE,
# Data args
data = data,
TrainOnFull = FALSE,
ValidationData = NULL,
TestData = NULL,
TargetColumnName = "Adrian",
FeatureColNames = names(data)[!names(data) %in%
c("IDcol_1", "IDcol_2","Adrian")],
WeightsColumnName = NULL,
IDcols = c("IDcol_1","IDcol_2"),
# Model evaluation args
eval_metric = "merror",
LossFunction = 'multi:softprob',
grid_eval_metric = "accuracy",
NumOfParDepPlots = 3L,
# Grid tuning args
PassInGrid = NULL,
GridTune = FALSE,
BaselineComparison = "default",
MaxModelsInGrid = 10L,
MaxRunsWithoutNewWinner = 20L,
MaxRunMinutes = 24L*60L,
Verbose = 1L,
DebugMode = FALSE,
# ML args
Trees = 50L,
eta = 0.05,
max_depth = 4L,
min_child_weight = 1.0,
subsample = 0.55,
colsample_bytree = 0.55)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.