Unverified Commit 4c8418ea authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[docs] R docs cleanup (#2375)

* R docs cleanup

* regenerated R documentation files
parent df26b65d
...@@ -635,9 +635,9 @@ Dataset <- R6::R6Class( ...@@ -635,9 +635,9 @@ Dataset <- R6::R6Class(
) )
) )
#' Construct lgb.Dataset object #' Construct \code{lgb.Dataset} object
#' #'
#' Construct lgb.Dataset object from dense matrix, sparse matrix #' Construct \code{lgb.Dataset} object from dense matrix, sparse matrix
#' or local file (that was created previously by saving an \code{lgb.Dataset}). #' or local file (that was created previously by saving an \code{lgb.Dataset}).
#' #'
#' @param data a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename #' @param data a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename
...@@ -646,7 +646,7 @@ Dataset <- R6::R6Class( ...@@ -646,7 +646,7 @@ Dataset <- R6::R6Class(
#' @param colnames names of columns #' @param colnames names of columns
#' @param categorical_feature categorical features #' @param categorical_feature categorical features
#' @param free_raw_data TRUE for need to free raw data after construct #' @param free_raw_data TRUE for need to free raw data after construct
#' @param info a list of information of the lgb.Dataset object #' @param info a list of information of the \code{lgb.Dataset} object
#' @param ... other information to pass to \code{info} or parameters pass to \code{params} #' @param ... other information to pass to \code{info} or parameters pass to \code{params}
#' #'
#' @return constructed dataset #' @return constructed dataset
...@@ -690,7 +690,7 @@ lgb.Dataset <- function(data, ...@@ -690,7 +690,7 @@ lgb.Dataset <- function(data,
#' #'
#' @param dataset \code{lgb.Dataset} object, training data #' @param dataset \code{lgb.Dataset} object, training data
#' @param data a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename #' @param data a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename
#' @param info a list of information of the lgb.Dataset object #' @param info a list of information of the \code{lgb.Dataset} object
#' @param ... other information to pass to \code{info}. #' @param ... other information to pass to \code{info}.
#' #'
#' @return constructed dataset #' @return constructed dataset
...@@ -741,7 +741,7 @@ lgb.Dataset.construct <- function(dataset) { ...@@ -741,7 +741,7 @@ lgb.Dataset.construct <- function(dataset) {
} }
#' Dimensions of an lgb.Dataset #' Dimensions of an \code{lgb.Dataset}
#' #'
#' Returns a vector of numbers of rows and of columns in an \code{lgb.Dataset}. #' Returns a vector of numbers of rows and of columns in an \code{lgb.Dataset}.
#' @param x Object of class \code{lgb.Dataset} #' @param x Object of class \code{lgb.Dataset}
...@@ -852,9 +852,9 @@ dimnames.lgb.Dataset <- function(x) { ...@@ -852,9 +852,9 @@ dimnames.lgb.Dataset <- function(x) {
#' Slice a dataset #' Slice a dataset
#' #'
#' Get a new \code{lgb.Dataset} containing the specified rows of #' Get a new \code{lgb.Dataset} containing the specified rows of
#' original lgb.Dataset object #' original \code{lgb.Dataset} object
#' #'
#' @param dataset Object of class "lgb.Dataset" #' @param dataset Object of class \code{lgb.Dataset}
#' @param idxset a integer vector of indices of rows needed #' @param idxset a integer vector of indices of rows needed
#' @param ... other parameters (currently not used) #' @param ... other parameters (currently not used)
#' @return constructed sub dataset #' @return constructed sub dataset
...@@ -888,7 +888,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { ...@@ -888,7 +888,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {
} }
#' Get information of an lgb.Dataset object #' Get information of an \code{lgb.Dataset} object
#' #'
#' @param dataset Object of class \code{lgb.Dataset} #' @param dataset Object of class \code{lgb.Dataset}
#' @param name the name of the information field to get (see details) #' @param name the name of the information field to get (see details)
...@@ -901,8 +901,8 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { ...@@ -901,8 +901,8 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {
#' \itemize{ #' \itemize{
#' \item \code{label}: label lightgbm learn from ; #' \item \code{label}: label lightgbm learn from ;
#' \item \code{weight}: to do a weight rescale ; #' \item \code{weight}: to do a weight rescale ;
#' \item \code{group}: group size #' \item \code{group}: group size ;
#' \item \code{init_score}: initial score is the base prediction lightgbm will boost from ; #' \item \code{init_score}: initial score is the base prediction lightgbm will boost from.
#' } #' }
#' #'
#' @examples #' @examples
...@@ -937,9 +937,9 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) { ...@@ -937,9 +937,9 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) {
} }
#' Set information of an lgb.Dataset object #' Set information of an \code{lgb.Dataset} object
#' #'
#' @param dataset Object of class "lgb.Dataset" #' @param dataset Object of class \code{lgb.Dataset}
#' @param name the name of the field to get #' @param name the name of the field to get
#' @param info the specific field of information to set #' @param info the specific field of information to set
#' @param ... other parameters #' @param ... other parameters
......
#' Data preparator for LightGBM datasets (numeric) #' Data preparator for LightGBM datasets (numeric)
#' #'
#' Attempts to prepare a clean dataset to prepare to put in a lgb.Dataset. Factors and characters are converted to numeric without integers. Please use \code{lgb.prepare_rules} if you want to apply this transformation to other datasets. #' Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. Factors and characters are converted to numeric without integers. Please use \code{lgb.prepare_rules} if you want to apply this transformation to other datasets.
#' #'
#' @param data A data.frame or data.table to prepare. #' @param data A data.frame or data.table to prepare.
#' #'
#' @return The cleaned dataset. It must be converted to a matrix format (\code{as.matrix}) for input in lgb.Dataset. #' @return The cleaned dataset. It must be converted to a matrix format (\code{as.matrix}) for input in \code{lgb.Dataset}.
#' #'
#' @examples #' @examples
#' library(lightgbm) #' library(lightgbm)
#' data(iris) #' data(iris)
#' #'
#' str(iris) #' str(iris)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 ...
#' #'
#' str(lgb.prepare(data = iris)) # Convert all factors/chars to numeric #' str(lgb.prepare(data = iris)) # Convert all factors/chars to numeric
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : num 1 1 1 1 1 1 1 1 1 1 ...
#' #'
#' \dontrun{ #' \dontrun{
#' # When lightgbm package is installed, and you do not want to load it #' # When lightgbm package is installed, and you do not want to load it
......
#' Data preparator for LightGBM datasets (integer) #' Data preparator for LightGBM datasets (integer)
#' #'
#' Attempts to prepare a clean dataset to prepare to put in a lgb.Dataset. Factors and characters are converted to numeric (specifically: integer). Please use \code{lgb.prepare_rules2} if you want to apply this transformation to other datasets. This is useful if you have a specific need for integer dataset instead of numeric dataset. Note that there are programs which do not support integer-only input. Consider this as a half memory technique which is dangerous, especially for LightGBM. #' Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. Factors and characters are converted to numeric (specifically: integer). Please use \code{lgb.prepare_rules2} if you want to apply this transformation to other datasets. This is useful if you have a specific need for integer dataset instead of numeric dataset. Note that there are programs which do not support integer-only input. Consider this as a half memory technique which is dangerous, especially for LightGBM.
#' #'
#' @param data A data.frame or data.table to prepare. #' @param data A data.frame or data.table to prepare.
#' #'
#' @return The cleaned dataset. It must be converted to a matrix format (\code{as.matrix}) for input in lgb.Dataset. #' @return The cleaned dataset. It must be converted to a matrix format (\code{as.matrix}) for input in \code{lgb.Dataset}.
#' #'
#' @examples #' @examples
#' library(lightgbm) #' library(lightgbm)
#' data(iris) #' data(iris)
#' #'
#' str(iris) #' str(iris)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 ...
#' #'
#' # Convert all factors/chars to integer #' # Convert all factors/chars to integer
#' str(lgb.prepare2(data = iris)) #' str(lgb.prepare2(data = iris))
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : int 1 1 1 1 1 1 1 1 1 1 ...
#' #'
#' \dontrun{ #' \dontrun{
#' # When lightgbm package is installed, and you do not want to load it #' # When lightgbm package is installed, and you do not want to load it
......
#' Data preparator for LightGBM datasets with rules (numeric) #' Data preparator for LightGBM datasets with rules (numeric)
#' #'
#' Attempts to prepare a clean dataset to prepare to put in a lgb.Dataset. Factors and characters are converted to numeric. In addition, keeps rules created so you can convert other datasets using this converter. #' Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. Factors and characters are converted to numeric. In addition, keeps rules created so you can convert other datasets using this converter.
#' #'
#' @param data A data.frame or data.table to prepare. #' @param data A data.frame or data.table to prepare.
#' @param rules A set of rules from the data preparator, if already used. #' @param rules A set of rules from the data preparator, if already used.
#' #'
#' @return A list with the cleaned dataset (\code{data}) and the rules (\code{rules}). The data must be converted to a matrix format (\code{as.matrix}) for input in lgb.Dataset. #' @return A list with the cleaned dataset (\code{data}) and the rules (\code{rules}). The data must be converted to a matrix format (\code{as.matrix}) for input in \code{lgb.Dataset}.
#' #'
#' @examples #' @examples
#' library(lightgbm) #' library(lightgbm)
#' data(iris) #' data(iris)
#' #'
#' str(iris) #' str(iris)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 ...
#' #'
#' new_iris <- lgb.prepare_rules(data = iris) # Autoconverter #' new_iris <- lgb.prepare_rules(data = iris) # Autoconverter
#' str(new_iris$data) #' str(new_iris$data)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : num 1 1 1 1 1 1 1 1 1 1 ...
#' #'
#' data(iris) # Erase iris dataset #' data(iris) # Erase iris dataset
#' iris$Species[1] <- "NEW FACTOR" # Introduce junk factor (NA) #' iris$Species[1] <- "NEW FACTOR" # Introduce junk factor (NA)
#' # Warning message:
#' # In `[<-.factor`(`*tmp*`, 1, value = c(NA, 1L, 1L, 1L, 1L, 1L, 1L, :
#' # invalid factor level, NA generated
#' #'
#' # Use conversion using known rules #' # Use conversion using known rules
#' # Unknown factors become 0, excellent for sparse datasets #' # Unknown factors become 0, excellent for sparse datasets
...@@ -40,14 +25,11 @@ ...@@ -40,14 +25,11 @@
#' #'
#' # Unknown factor is now zero, perfect for sparse datasets #' # Unknown factor is now zero, perfect for sparse datasets
#' newer_iris$data[1, ] # Species became 0 as it is an unknown factor #' newer_iris$data[1, ] # Species became 0 as it is an unknown factor
#' # Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#' # 1 5.1 3.5 1.4 0.2 0
#' #'
#' newer_iris$data[1, 5] <- 1 # Put back real initial value #' newer_iris$data[1, 5] <- 1 # Put back real initial value
#' #'
#' # Is the newly created dataset equal? YES! #' # Is the newly created dataset equal? YES!
#' all.equal(new_iris$data, newer_iris$data) #' all.equal(new_iris$data, newer_iris$data)
#' # [1] TRUE
#' #'
#' # Can we test our own rules? #' # Can we test our own rules?
#' data(iris) # Erase iris dataset #' data(iris) # Erase iris dataset
...@@ -58,12 +40,6 @@ ...@@ -58,12 +40,6 @@
#' "virginica" = 1)) #' "virginica" = 1))
#' newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules) #' newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules)
#' str(newest_iris$data) # SUCCESS! #' str(newest_iris$data) # SUCCESS!
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : num 3 3 3 3 3 3 3 3 3 3 ...
#' #'
#' @importFrom data.table set #' @importFrom data.table set
#' @export #' @export
......
#' Data preparator for LightGBM datasets with rules (integer) #' Data preparator for LightGBM datasets with rules (integer)
#' #'
#' Attempts to prepare a clean dataset to prepare to put in a lgb.Dataset. Factors and characters are converted to numeric (specifically: integer). In addition, keeps rules created so you can convert other datasets using this converter. This is useful if you have a specific need for integer dataset instead of numeric dataset. Note that there are programs which do not support integer-only input. Consider this as a half memory technique which is dangerous, especially for LightGBM. #' Attempts to prepare a clean dataset to prepare to put in a \code{lgb.Dataset}. Factors and characters are converted to numeric (specifically: integer). In addition, keeps rules created so you can convert other datasets using this converter. This is useful if you have a specific need for integer dataset instead of numeric dataset. Note that there are programs which do not support integer-only input. Consider this as a half memory technique which is dangerous, especially for LightGBM.
#' #'
#' @param data A data.frame or data.table to prepare. #' @param data A data.frame or data.table to prepare.
#' @param rules A set of rules from the data preparator, if already used. #' @param rules A set of rules from the data preparator, if already used.
#' #'
#' @return A list with the cleaned dataset (\code{data}) and the rules (\code{rules}). The data must be converted to a matrix format (\code{as.matrix}) for input in lgb.Dataset. #' @return A list with the cleaned dataset (\code{data}) and the rules (\code{rules}). The data must be converted to a matrix format (\code{as.matrix}) for input in \code{lgb.Dataset}.
#' #'
#' @examples #' @examples
#' library(lightgbm) #' library(lightgbm)
#' data(iris) #' data(iris)
#' #'
#' str(iris) #' str(iris)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 ...
#' #'
#' new_iris <- lgb.prepare_rules2(data = iris) # Autoconverter #' new_iris <- lgb.prepare_rules2(data = iris) # Autoconverter
#' str(new_iris$data) #' str(new_iris$data)
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : int 1 1 1 1 1 1 1 1 1 1 ...
#' #'
#' data(iris) # Erase iris dataset #' data(iris) # Erase iris dataset
#' iris$Species[1] <- "NEW FACTOR" # Introduce junk factor (NA) #' iris$Species[1] <- "NEW FACTOR" # Introduce junk factor (NA)
#' # Warning message:
#' # In `[<-.factor`(`*tmp*`, 1, value = c(NA, 1L, 1L, 1L, 1L, 1L, 1L, :
#' # invalid factor level, NA generated
#' #'
#' # Use conversion using known rules #' # Use conversion using known rules
#' # Unknown factors become 0, excellent for sparse datasets #' # Unknown factors become 0, excellent for sparse datasets
...@@ -40,14 +25,11 @@ ...@@ -40,14 +25,11 @@
#' #'
#' # Unknown factor is now zero, perfect for sparse datasets #' # Unknown factor is now zero, perfect for sparse datasets
#' newer_iris$data[1, ] # Species became 0 as it is an unknown factor #' newer_iris$data[1, ] # Species became 0 as it is an unknown factor
#' # Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#' # 1 5.1 3.5 1.4 0.2 0
#' #'
#' newer_iris$data[1, 5] <- 1 # Put back real initial value #' newer_iris$data[1, 5] <- 1 # Put back real initial value
#' #'
#' # Is the newly created dataset equal? YES! #' # Is the newly created dataset equal? YES!
#' all.equal(new_iris$data, newer_iris$data) #' all.equal(new_iris$data, newer_iris$data)
#' # [1] TRUE
#' #'
#' # Can we test our own rules? #' # Can we test our own rules?
#' data(iris) # Erase iris dataset #' data(iris) # Erase iris dataset
...@@ -58,12 +40,6 @@ ...@@ -58,12 +40,6 @@
#' "virginica" = 1L)) #' "virginica" = 1L))
#' newest_iris <- lgb.prepare_rules2(data = iris, rules = personal_rules) #' newest_iris <- lgb.prepare_rules2(data = iris, rules = personal_rules)
#' str(newest_iris$data) # SUCCESS! #' str(newest_iris$data) # SUCCESS!
#' # 'data.frame': 150 obs. of 5 variables:
#' # $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#' # $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#' # $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#' # $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#' # $ Species : int 3 3 3 3 3 3 3 3 3 3 ...
#' #'
#' @importFrom data.table set #' @importFrom data.table set
#' @export #' @export
......
#' readRDS for lgb.Booster models #' readRDS for \code{lgb.Booster} models
#' #'
#' Attempts to load a model using RDS. #' Attempts to load a model using RDS.
#' #'
#' @param file a connection or the name of the file where the R object is saved to or read from. #' @param file a connection or the name of the file where the R object is saved to or read from.
#' @param refhook a hook function for handling reference objects. #' @param refhook a hook function for handling reference objects.
#' #'
#' @return lgb.Booster. #' @return \code{lgb.Booster}.
#' #'
#' @examples #' @examples
#' library(lightgbm) #' library(lightgbm)
......
#' saveRDS for lgb.Booster models #' saveRDS for \code{lgb.Booster} models
#' #'
#' Attempts to save a model using RDS. Has an additional parameter (\code{raw}) which decides whether to save the raw model or not. #' Attempts to save a model using RDS. Has an additional parameter (\code{raw}) which decides whether to save the raw model or not.
#' #'
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
% Please edit documentation in R/lgb.Dataset.R % Please edit documentation in R/lgb.Dataset.R
\name{dim.lgb.Dataset} \name{dim.lgb.Dataset}
\alias{dim.lgb.Dataset} \alias{dim.lgb.Dataset}
\title{Dimensions of an lgb.Dataset} \title{Dimensions of an \code{lgb.Dataset}}
\usage{ \usage{
\method{dim}{lgb.Dataset}(x, ...) \method{dim}{lgb.Dataset}(x, ...)
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\name{getinfo} \name{getinfo}
\alias{getinfo} \alias{getinfo}
\alias{getinfo.lgb.Dataset} \alias{getinfo.lgb.Dataset}
\title{Get information of an lgb.Dataset object} \title{Get information of an \code{lgb.Dataset} object}
\usage{ \usage{
getinfo(dataset, ...) getinfo(dataset, ...)
...@@ -20,7 +20,7 @@ getinfo(dataset, ...) ...@@ -20,7 +20,7 @@ getinfo(dataset, ...)
info data info data
} }
\description{ \description{
Get information of an lgb.Dataset object Get information of an \code{lgb.Dataset} object
} }
\details{ \details{
The \code{name} field can be one of the following: The \code{name} field can be one of the following:
...@@ -28,8 +28,8 @@ The \code{name} field can be one of the following: ...@@ -28,8 +28,8 @@ The \code{name} field can be one of the following:
\itemize{ \itemize{
\item \code{label}: label lightgbm learn from ; \item \code{label}: label lightgbm learn from ;
\item \code{weight}: to do a weight rescale ; \item \code{weight}: to do a weight rescale ;
\item \code{group}: group size \item \code{group}: group size ;
\item \code{init_score}: initial score is the base prediction lightgbm will boost from ; \item \code{init_score}: initial score is the base prediction lightgbm will boost from.
} }
} }
\examples{ \examples{
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
% Please edit documentation in R/lgb.Dataset.R % Please edit documentation in R/lgb.Dataset.R
\name{lgb.Dataset} \name{lgb.Dataset}
\alias{lgb.Dataset} \alias{lgb.Dataset}
\title{Construct lgb.Dataset object} \title{Construct \code{lgb.Dataset} object}
\usage{ \usage{
lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL, lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL,
categorical_feature = NULL, free_raw_data = TRUE, info = list(), categorical_feature = NULL, free_raw_data = TRUE, info = list(),
...@@ -21,7 +21,7 @@ lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL, ...@@ -21,7 +21,7 @@ lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL,
\item{free_raw_data}{TRUE for need to free raw data after construct} \item{free_raw_data}{TRUE for need to free raw data after construct}
\item{info}{a list of information of the lgb.Dataset object} \item{info}{a list of information of the \code{lgb.Dataset} object}
\item{...}{other information to pass to \code{info} or parameters pass to \code{params}} \item{...}{other information to pass to \code{info} or parameters pass to \code{params}}
} }
...@@ -29,7 +29,7 @@ lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL, ...@@ -29,7 +29,7 @@ lgb.Dataset(data, params = list(), reference = NULL, colnames = NULL,
constructed dataset constructed dataset
} }
\description{ \description{
Construct lgb.Dataset object from dense matrix, sparse matrix Construct \code{lgb.Dataset} object from dense matrix, sparse matrix
or local file (that was created previously by saving an \code{lgb.Dataset}). or local file (that was created previously by saving an \code{lgb.Dataset}).
} }
\examples{ \examples{
......
...@@ -11,7 +11,7 @@ lgb.Dataset.create.valid(dataset, data, info = list(), ...) ...@@ -11,7 +11,7 @@ lgb.Dataset.create.valid(dataset, data, info = list(), ...)
\item{data}{a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename} \item{data}{a \code{matrix} object, a \code{dgCMatrix} object or a character representing a filename}
\item{info}{a list of information of the lgb.Dataset object} \item{info}{a list of information of the \code{lgb.Dataset} object}
\item{...}{other information to pass to \code{info}.} \item{...}{other information to pass to \code{info}.}
} }
......
...@@ -18,7 +18,6 @@ passed dataset ...@@ -18,7 +18,6 @@ passed dataset
Save \code{lgb.Dataset} to a binary file Save \code{lgb.Dataset} to a binary file
} }
\examples{ \examples{
library(lightgbm) library(lightgbm)
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
train <- agaricus.train train <- agaricus.train
......
...@@ -92,8 +92,8 @@ params <- list(objective = "regression", metric = "l2") ...@@ -92,8 +92,8 @@ params <- list(objective = "regression", metric = "l2")
model <- lgb.cv(params, model <- lgb.cv(params,
dtrain, dtrain,
10, 10,
nfold = 5, nfold = 3,
min_data = 1, min_data = 1,
learning_rate = 1, learning_rate = 1,
early_stopping_rounds = 10) early_stopping_rounds = 5)
} }
...@@ -29,11 +29,11 @@ params <- list(objective = "regression", metric = "l2") ...@@ -29,11 +29,11 @@ params <- list(objective = "regression", metric = "l2")
valids <- list(test = dtest) valids <- list(test = dtest)
model <- lgb.train(params, model <- lgb.train(params,
dtrain, dtrain,
100, 10,
valids, valids,
min_data = 1, min_data = 1,
learning_rate = 1, learning_rate = 1,
early_stopping_rounds = 10) early_stopping_rounds = 5)
json_model <- lgb.dump(model) json_model <- lgb.dump(model)
} }
...@@ -36,11 +36,10 @@ params <- list(objective = "regression", metric = "l2") ...@@ -36,11 +36,10 @@ params <- list(objective = "regression", metric = "l2")
valids <- list(test = dtest) valids <- list(test = dtest)
model <- lgb.train(params, model <- lgb.train(params,
dtrain, dtrain,
100, 10,
valids, valids,
min_data = 1, min_data = 1,
learning_rate = 1, learning_rate = 1,
early_stopping_rounds = 10) early_stopping_rounds = 5)
lgb.get.eval.result(model, "test", "l2") lgb.get.eval.result(model, "test", "l2")
} }
...@@ -32,8 +32,7 @@ dtrain <- lgb.Dataset(train$data, label = train$label) ...@@ -32,8 +32,7 @@ dtrain <- lgb.Dataset(train$data, label = train$label)
params <- list(objective = "binary", params <- list(objective = "binary",
learning_rate = 0.01, num_leaves = 63, max_depth = -1, learning_rate = 0.01, num_leaves = 63, max_depth = -1,
min_data_in_leaf = 1, min_sum_hessian_in_leaf = 1) min_data_in_leaf = 1, min_sum_hessian_in_leaf = 1)
model <- lgb.train(params, dtrain, 20) model <- lgb.train(params, dtrain, 10)
model <- lgb.train(params, dtrain, 20)
tree_imp1 <- lgb.importance(model, percentage = TRUE) tree_imp1 <- lgb.importance(model, percentage = TRUE)
tree_imp2 <- lgb.importance(model, percentage = FALSE) tree_imp2 <- lgb.importance(model, percentage = FALSE)
......
...@@ -44,7 +44,7 @@ params <- list( ...@@ -44,7 +44,7 @@ params <- list(
, min_data_in_leaf = 1 , min_data_in_leaf = 1
, min_sum_hessian_in_leaf = 1 , min_sum_hessian_in_leaf = 1
) )
model <- lgb.train(params, dtrain, 20) model <- lgb.train(params, dtrain, 10)
tree_interpretation <- lgb.interprete(model, test$data, 1:5) tree_interpretation <- lgb.interprete(model, test$data, 1:5)
......
...@@ -31,11 +31,11 @@ params <- list(objective = "regression", metric = "l2") ...@@ -31,11 +31,11 @@ params <- list(objective = "regression", metric = "l2")
valids <- list(test = dtest) valids <- list(test = dtest)
model <- lgb.train(params, model <- lgb.train(params,
dtrain, dtrain,
100, 10,
valids, valids,
min_data = 1, min_data = 1,
learning_rate = 1, learning_rate = 1,
early_stopping_rounds = 10) early_stopping_rounds = 5)
lgb.save(model, "model.txt") lgb.save(model, "model.txt")
load_booster <- lgb.load(filename = "model.txt") load_booster <- lgb.load(filename = "model.txt")
model_string <- model$save_model_to_string(NULL) # saves best iteration model_string <- model$save_model_to_string(NULL) # saves best iteration
......
...@@ -47,8 +47,7 @@ dtrain <- lgb.Dataset(train$data, label = train$label) ...@@ -47,8 +47,7 @@ dtrain <- lgb.Dataset(train$data, label = train$label)
params <- list(objective = "binary", params <- list(objective = "binary",
learning_rate = 0.01, num_leaves = 63, max_depth = -1, learning_rate = 0.01, num_leaves = 63, max_depth = -1,
min_data_in_leaf = 1, min_sum_hessian_in_leaf = 1) min_data_in_leaf = 1, min_sum_hessian_in_leaf = 1)
model <- lgb.train(params, dtrain, 20) model <- lgb.train(params, dtrain, 10)
model <- lgb.train(params, dtrain, 20)
tree_dt <- lgb.model.dt.tree(model) tree_dt <- lgb.model.dt.tree(model)
......
...@@ -43,7 +43,7 @@ params <- list( ...@@ -43,7 +43,7 @@ params <- list(
, min_sum_hessian_in_leaf = 1 , min_sum_hessian_in_leaf = 1
) )
model <- lgb.train(params, dtrain, 20) model <- lgb.train(params, dtrain, 10)
tree_imp <- lgb.importance(model, percentage = TRUE) tree_imp <- lgb.importance(model, percentage = TRUE)
lgb.plot.importance(tree_imp, top_n = 10, measure = "Gain") lgb.plot.importance(tree_imp, top_n = 10, measure = "Gain")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment