lightgbm.R 2.55 KB
Newer Older
1
2
3
#' Simple interface for training an lightgbm model.
#' Its documentation is combined with lgb.train.
#'
Guolin Ke's avatar
Guolin Ke committed
4
5
6
#' @rdname lgb.train
#' @export
lightgbm <- function(data, label = NULL, weight = NULL,
7
8
                    params = list(), nrounds = 10,
                    verbose = 1, eval_freq = 1L,
Guolin Ke's avatar
Guolin Ke committed
9
10
11
                    early_stopping_rounds = NULL,
                    save_name = "lightgbm.model",
                    init_model = NULL, callbacks = list(), ...) {
Guolin Ke's avatar
Guolin Ke committed
12
  dtrain <- data
13
14
  if (!lgb.is.Dataset(dtrain)) {
    dtrain <- lgb.Dataset(data, label = label, weight = weight)
Guolin Ke's avatar
Guolin Ke committed
15
  }
Guolin Ke's avatar
Guolin Ke committed
16
17

  valids <- list()
18
  if (verbose > 0) { valids$train = dtrain }
Guolin Ke's avatar
Guolin Ke committed
19

20
  bst <- lgb.train(params, dtrain, nrounds, valids, verbose = verbose, eval_freq = eval_freq,
Guolin Ke's avatar
Guolin Ke committed
21
22
23
                   early_stopping_rounds = early_stopping_rounds,
                   init_model = init_model, callbacks = callbacks, ...)
  bst$save_model(save_name)
24
  bst
Guolin Ke's avatar
Guolin Ke committed
25
26
27
}

#' Training part from Mushroom Data Set
28
#'
Guolin Ke's avatar
Guolin Ke committed
29
30
#' This data set is originally from the Mushroom data set,
#' UCI Machine Learning Repository.
31
#'
Guolin Ke's avatar
Guolin Ke committed
32
#' This data set includes the following fields:
33
#'
Guolin Ke's avatar
Guolin Ke committed
34
35
36
37
38
39
40
#' \itemize{
#'  \item \code{label} the label for each record
#'  \item \code{data} a sparse Matrix of \code{dgCMatrix} class, with 126 columns.
#' }
#'
#' @references
#' https://archive.ics.uci.edu/ml/datasets/Mushroom
41
42
43
#'
#' Bache, K. & Lichman, M. (2013). UCI Machine Learning Repository
#' [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California,
Guolin Ke's avatar
Guolin Ke committed
44
#' School of Information and Computer Science.
45
#'
Guolin Ke's avatar
Guolin Ke committed
46
47
48
49
#' @docType data
#' @keywords datasets
#' @name agaricus.train
#' @usage data(agaricus.train)
50
#' @format A list containing a label vector, and a dgCMatrix object with 6513
Guolin Ke's avatar
Guolin Ke committed
51
52
53
54
55
56
57
#' rows and 127 variables
NULL

#' Test part from Mushroom Data Set
#'
#' This data set is originally from the Mushroom data set,
#' UCI Machine Learning Repository.
58
#'
Guolin Ke's avatar
Guolin Ke committed
59
#' This data set includes the following fields:
60
#'
Guolin Ke's avatar
Guolin Ke committed
61
62
63
64
65
66
67
#' \itemize{
#'  \item \code{label} the label for each record
#'  \item \code{data} a sparse Matrix of \code{dgCMatrix} class, with 126 columns.
#' }
#'
#' @references
#' https://archive.ics.uci.edu/ml/datasets/Mushroom
68
69
70
#'
#' Bache, K. & Lichman, M. (2013). UCI Machine Learning Repository
#' [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California,
Guolin Ke's avatar
Guolin Ke committed
71
#' School of Information and Computer Science.
72
#'
Guolin Ke's avatar
Guolin Ke committed
73
74
75
76
#' @docType data
#' @keywords datasets
#' @name agaricus.test
#' @usage data(agaricus.test)
77
#' @format A list containing a label vector, and a dgCMatrix object with 1611
Guolin Ke's avatar
Guolin Ke committed
78
79
80
81
#' rows and 126 variables
NULL

# Various imports
Guolin Ke's avatar
Guolin Ke committed
82
#' @import methods
Guolin Ke's avatar
Guolin Ke committed
83
84
#' @importFrom R6 R6Class
#' @useDynLib lightgbm
85
NULL