Description Usage Arguments Value Examples
View source: R/Laurae.xgb.dmat.R
Geneartes a (list of) xgb.DMatrix. Supported for clusters. Requires Matrix and xgboost packages.
1 2  | 
data | 
 Type: matrix or dgCMatrix or data.frame or data.table or filename, or potentially a list of any of them. When a list is provided, it generates the appropriate   | 
label | 
 Type: numeric, or a list of numeric. The label of associated rows in   | 
missing | 
 Type: numeric. The value used to represent missing values in   | 
save_names | 
 Type: character or NULL, or a list of characters. If names are provided, the generated   | 
save_keep | 
 Type: logical, or a list of logicals. When names are provided,   | 
clean_mem | 
 Type: logical. Whether the force garbage collection at the end of each matrix construction in order to reclaim RAM. Defaults to   | 
progress_bar | 
 Type: logical. Whether to print a progress bar in case of list inputs. Defaults to   | 
... | 
 More arguments to pass to   | 
The xgb.DMatrix
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 28 29 30 31 32  | library(Matrix)
library(xgboost)
set.seed(0)
# Generate xgb.DMatrix from matrix
random_mat <- matrix(runif(10000, 0, 1), nrow = 1000)
random_labels <- runif(1000, 0, 1)
xgb_from_mat <- Laurae.xgb.dmat(data = random_mat, label = random_labels, missing = NA)
# Generate xgb.DMatrix from data.frame
random_df <- data.frame(random_mat)
random_labels_2 <- runif(1000, 0, 1)
xgb_from_df <- Laurae.xgb.dmat(data = random_df, label = random_labels, missing = NA)
# Generate xgb.DMatrix from respective elements of a list with progress bar
# while keeping memory usage as low as theoretically possible
random_list <- list(random_mat, random_df)
random_labels_3 <- list(random_labels, random_labels_2)
xgb_from_list <- Laurae.xgb.dmat(data = random_list,
                                 label = random_labels_3,
                                 missing = NA,
                                 progress_bar = TRUE,
                                 clean_mem = TRUE)
# Generate xgb.DMatrix from respective elements of a list and keep only first
# while keeping memory usage as low as theoretically possible
xgb_from_list <- Laurae.xgb.dmat(data = random_list,
                                 label = random_labels_3,
                                 missing = NA,
                                 save_keep = c(TRUE, FALSE),
                                 clean_mem = TRUE)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.