Description Usage Arguments Value Examples
View source: R/model_lightgbm.R
Train LightGBM with cross-validation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
df.train |
data.frame for train set |
df.valid |
data.frame for valid set |
fnames |
all feature names |
label |
label name |
fnames.cat |
categorical feature names |
id |
colnames of id, if not provide, default to use rowname |
rules |
rules to index categorical features |
params |
list of params for lightgbm |
cv.verbose |
whether verbose when cv |
train.verbose |
whether verbose when train |
cv |
whether perform a k-fold cross validation, default at FALSE |
nfold |
number of folds of cross validation, if cv is TRUE |
score.fun |
score functino for validation, defaults to auc |
... |
other parameters in |
list of (model, rules, fnames)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | label <- 'label'
fnames <- c('Sex','Class','Age','Freq')
fnames.cat <- c('Sex','Age','Class')
df <- data.frame(Titanic)
df$label <- ifelse(df$Survived == "Yes", 1 ,0)
in.train <- runif(nrow(df)) < 0.8
df.train <- df[in.train, ]
df.valid <- df[!in.train, ]
bst <- lgb.train_with_cv(df.train, df.valid,
fnames = fnames,
label = label,
fnames.cat = fnames.cat,
rules = NULL, cv = TRUE,
num_leaves = 63,
learning_rate = 1.0,
nrounds = 10L,
min_data = 1L,
cv.verbose = 1,
train.verbose = 1,
eval = 'auc',
eval_freq = 10,
nfold = 2L,
early_stopping_rounds = 5L,
objective = "binary")
lgb.save_model(bst, './saved_model','lgb_baseline', verbose = TRUE)
bst.loaded <- lgb.load_model('./saved_model','lgb_baseline')
preds <- lgb.predict(bst.loaded, df.valid)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.