View source: R/AutoLightGBMClassifier.R
AutoLightGBMClassifier | R Documentation |
AutoLightGBMClassifier is an automated lightgbm modeling framework with grid-tuning and model evaluation that runs a variety of steps. First, 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 plot, evaluation boxplot, evaluation metrics, variable importance, partial dependence calibration plots, partial dependence calibration box plots, and column names used in model fitting.
AutoLightGBMClassifier(
data = NULL,
TrainOnFull = FALSE,
ValidationData = NULL,
TestData = NULL,
TargetColumnName = NULL,
FeatureColNames = NULL,
PrimaryDateColumn = NULL,
IDcols = NULL,
WeightsColumnName = NULL,
CostMatrixWeights = c(1, 0, 0, 1),
EncodingMethod = "credibility",
OutputSelection = c("Importances", "EvalPlots", "EvalMetrics", "Score_TrainData"),
model_path = NULL,
metadata_path = NULL,
DebugMode = FALSE,
SaveInfoToPDF = FALSE,
ModelID = "TestModel",
ReturnFactorLevels = TRUE,
ReturnModelObjects = TRUE,
SaveModelObjects = FALSE,
NumOfParDepPlots = 3L,
Verbose = 0L,
GridTune = FALSE,
grid_eval_metric = "Utility",
BaselineComparison = "default",
MaxModelsInGrid = 10L,
MaxRunsWithoutNewWinner = 20L,
MaxRunMinutes = 24L * 60L,
PassInGrid = NULL,
input_model = NULL,
task = "train",
device_type = "CPU",
NThreads = parallel::detectCores()/2,
objective = "binary",
metric = "binary_logloss",
boosting = "gbdt",
LinearTree = FALSE,
Trees = 50L,
eta = NULL,
num_leaves = 31,
deterministic = TRUE,
force_col_wise = FALSE,
force_row_wise = FALSE,
max_depth = NULL,
min_data_in_leaf = 20,
min_sum_hessian_in_leaf = 0.001,
bagging_freq = 0,
bagging_fraction = 1,
feature_fraction = 1,
feature_fraction_bynode = 1,
extra_trees = FALSE,
early_stopping_round = 10,
first_metric_only = TRUE,
max_delta_step = 0,
lambda_l1 = 0,
lambda_l2 = 0,
linear_lambda = 0,
min_gain_to_split = 0,
drop_rate_dart = 0.1,
max_drop_dart = 50,
skip_drop_dart = 0.5,
uniform_drop_dart = FALSE,
top_rate_goss = FALSE,
other_rate_goss = FALSE,
monotone_constraints = NULL,
monotone_constraints_method = "advanced",
monotone_penalty = 0,
forcedsplits_filename = NULL,
refit_decay_rate = 0.9,
path_smooth = 0,
max_bin = 255,
min_data_in_bin = 3,
data_random_seed = 1,
is_enable_sparse = TRUE,
enable_bundle = TRUE,
use_missing = TRUE,
zero_as_missing = FALSE,
two_round = FALSE,
convert_model = NULL,
convert_model_language = "cpp",
boost_from_average = TRUE,
is_unbalance = FALSE,
scale_pos_weight = 1,
is_provide_training_metric = TRUE,
eval_at = c(1, 2, 3, 4, 5),
num_machines = 1,
gpu_platform_id = -1,
gpu_device_id = -1,
gpu_use_dp = TRUE,
num_gpu = 1
)
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. |
TargetColumnName |
Either supply the target column name OR the column number where the target is located (but not mixed types). |
FeatureColNames |
Either supply the feature column names OR the column number where the target is located (but not mixed types) |
PrimaryDateColumn |
Supply a date or datetime column for catboost to utilize time as its basis for handling categorical features, instead of random shuffling |
IDcols |
A vector of column names or column numbers to keep in your data but not include in the modeling. |
WeightsColumnName |
Supply a column name for your weights column. Leave NULL otherwise |
CostMatrixWeights |
= c(1,0,0,1) |
EncodingMethod |
Choose from 'binary', 'm_estimator', 'credibility', 'woe', 'target_encoding', 'poly_encode', 'backward_difference', 'helmert' |
OutputSelection |
You can select what type of output you want returned. Choose from c("Importances", "EvalPlots", "EvalMetrics", "Score_TrainData") |
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. |
DebugMode |
Set to TRUE to get a print out of the steps taken throughout the function |
SaveInfoToPDF |
Set to TRUE to save model insights to pdf |
ModelID |
A character string to name your model and output |
ReturnFactorLevels |
Set to TRUE to have the factor levels returned with the other model objects |
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 |
NumOfParDepPlots |
Tell the function the number of partial dependence calibration plots you want to create. |
Verbose |
Set to 0 if you want to suppress model evaluation updates in training |
GridTune |
Set to TRUE to run a grid tuning procedure. Set a number in MaxModelsInGrid to tell the procedure how many models you want to test. |
grid_eval_metric |
"mae", "mape", "rmse", "r2". Case sensitive |
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. # Core parameters https://lightgbm.readthedocs.io/en/latest/Parameters.html#core-parameter |
MaxModelsInGrid |
Number of models to test from grid options (243 total possible options) |
MaxRunsWithoutNewWinner |
Runs without new winner to end procedure |
MaxRunMinutes |
In minutes |
PassInGrid |
Default is NULL. Provide a data.table of grid options from a previous run. |
input_model |
= NULL, # continue training a model that is stored to fil |
task |
'train' or 'refit' |
device_type |
'cpu' or 'gpu' |
NThreads |
only list up to number of cores, not threads. parallel::detectCores() / 2 |
objective |
'binary' |
metric |
'binary_logloss', 'average_precision', 'auc', 'map', 'binary_error', 'auc_mu' |
boosting |
'gbdt', 'rf', 'dart', 'goss' |
LinearTree |
FALSE |
Trees |
50L |
eta |
NULL |
num_leaves |
31 |
deterministic |
TRUE # Learning Parameters https://lightgbm.readthedocs.io/en/latest/Parameters.html#learning-control-parameter |
force_col_wise |
FALSE |
force_row_wise |
FALSE |
max_depth |
NULL |
min_data_in_leaf |
20 |
min_sum_hessian_in_leaf |
0.001 |
bagging_freq |
0 |
bagging_fraction |
1.0 |
feature_fraction |
1.0 |
feature_fraction_bynode |
1.0 |
extra_trees |
FALSE |
early_stopping_round |
10 |
first_metric_only |
TRUE |
max_delta_step |
0.0 |
lambda_l1 |
0.0 |
lambda_l2 |
0.0 |
linear_lambda |
0.0 |
min_gain_to_split |
0 |
drop_rate_dart |
0.10 |
max_drop_dart |
50 |
skip_drop_dart |
0.50 |
uniform_drop_dart |
FALSE |
top_rate_goss |
FALSE |
other_rate_goss |
FALSE |
monotone_constraints |
"gbdt_prediction.cpp" |
monotone_constraints_method |
'advanced' |
monotone_penalty |
0.0 |
forcedsplits_filename |
NULL # use for AutoStack option; .json fil |
refit_decay_rate |
0.90 |
path_smooth |
0.0 # IO Dataset Parameters https://lightgbm.readthedocs.io/en/latest/Parameters.html#io-parameters |
max_bin |
255 |
min_data_in_bin |
3 |
data_random_seed |
1 |
is_enable_sparse |
TRUE |
enable_bundle |
TRUE |
use_missing |
TRUE |
zero_as_missing |
FALSE |
two_round |
FALSE # Convert Parameters # https://lightgbm.readthedocs.io/en/latest/Parameters.html#convert-parameters |
convert_model |
'gbdt_prediction.cpp' |
convert_model_language |
'cpp' # Objective Parameters https://lightgbm.readthedocs.io/en/latest/Parameters.html#objective-parameters |
boost_from_average |
TRUE |
is_unbalance |
FALSE |
scale_pos_weight |
1.0 # Metric Parameters (metric is in Core) |
is_provide_training_metric |
TRUE |
eval_at |
c(1,2,3,4,5) # Network Parameter |
num_machines |
1 # GPU Parameter |
gpu_platform_id |
-1 |
gpu_device_id |
-1 |
gpu_use_dp |
TRUE |
num_gpu |
1 |
Saves to file and returned in list: VariableImportance.csv, Model, ValidationData.csv, EvalutionPlot.png, EvalutionBoxPlot.png, EvaluationMetrics.csv, ParDepPlots.R a named list of features with partial dependence calibration plots, ParDepBoxPlots.R, GridCollect, and GridList
Adrian Antico
Other Automated Supervised Learning - Binary Classification:
AutoCatBoostClassifier()
,
AutoH2oDRFClassifier()
,
AutoH2oGAMClassifier()
,
AutoH2oGBMClassifier()
,
AutoH2oGLMClassifier()
,
AutoH2oMLClassifier()
,
AutoXGBoostClassifier()
## Not run:
# Create some dummy correlated data
data <- AutoQuant::FakeDataGenerator(
Correlation = 0.85,
N = 1000,
ID = 2,
ZIP = 0,
AddDate = FALSE,
Classification = TRUE,
MultiClass = FALSE)
# Run function
TestModel <- AutoQuant::AutoLightGBMClassifier(
# Metadata args
OutputSelection = c('Importances','EvalPlots','EvalMetrics','Score_TrainData'),
model_path = normalizePath("./"),
metadata_path = NULL,
ModelID = "Test_Model_1",
NumOfParDepPlots = 3L,
EncodingMethod = "credibility",
ReturnFactorLevels = TRUE,
ReturnModelObjects = TRUE,
SaveModelObjects = FALSE,
SaveInfoToPDF = FALSE,
DebugMode = 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")],
PrimaryDateColumn = NULL,
WeightsColumnName = NULL,
CostMatrixWeights = c(1,0,0,1),
IDcols = c("IDcol_1","IDcol_2"),
# Grid parameters
GridTune = FALSE,
grid_eval_metric = 'Utility',
BaselineComparison = 'default',
MaxModelsInGrid = 10L,
MaxRunsWithoutNewWinner = 20L,
MaxRunMinutes = 24L*60L,
PassInGrid = NULL,
# Core parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#core-parameters
input_model = NULL, # continue training a model that is stored to file
task = "train",
device_type = 'CPU',
NThreads = parallel::detectCores() / 2,
objective = 'binary',
metric = 'binary_logloss',
boosting = 'gbdt',
LinearTree = FALSE,
Trees = 50L,
eta = NULL,
num_leaves = 31,
deterministic = TRUE,
# Learning Parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#learning-control-parameters
force_col_wise = FALSE,
force_row_wise = FALSE,
max_depth = NULL,
min_data_in_leaf = 20,
min_sum_hessian_in_leaf = 0.001,
bagging_freq = 0,
bagging_fraction = 1.0,
feature_fraction = 1.0,
feature_fraction_bynode = 1.0,
extra_trees = FALSE,
early_stopping_round = 10,
first_metric_only = TRUE,
max_delta_step = 0.0,
lambda_l1 = 0.0,
lambda_l2 = 0.0,
linear_lambda = 0.0,
min_gain_to_split = 0,
drop_rate_dart = 0.10,
max_drop_dart = 50,
skip_drop_dart = 0.50,
uniform_drop_dart = FALSE,
top_rate_goss = FALSE,
other_rate_goss = FALSE,
monotone_constraints = NULL,
monotone_constraints_method = "advanced",
monotone_penalty = 0.0,
forcedsplits_filename = NULL, # use for AutoStack option; .json file
refit_decay_rate = 0.90,
path_smooth = 0.0,
# IO Dataset Parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#io-parameters
max_bin = 255,
min_data_in_bin = 3,
data_random_seed = 1,
is_enable_sparse = TRUE,
enable_bundle = TRUE,
use_missing = TRUE,
zero_as_missing = FALSE,
two_round = FALSE,
# Convert Parameters
convert_model = NULL,
convert_model_language = "cpp",
# Objective Parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#objective-parameters
boost_from_average = TRUE,
is_unbalance = FALSE,
scale_pos_weight = 1.0,
# Metric Parameters (metric is in Core)
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#metric-parameters
is_provide_training_metric = TRUE,
eval_at = c(1,2,3,4,5),
# Network Parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#network-parameters
num_machines = 1,
# GPU Parameters
# https://lightgbm.readthedocs.io/en/latest/Parameters.html#gpu-parameters
gpu_platform_id = -1,
gpu_device_id = -1,
gpu_use_dp = TRUE,
num_gpu = 1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.