"R-package/vscode:/vscode.git/clone" did not exist on "a2ae8384d1c8678fd401782d87bc2ae9a6cde0f0"
Commit 5457ef6b authored by James Lamb's avatar James Lamb Committed by Guolin Ke
Browse files

[R-package] removed horizontal whitespace (fixes #1642) (#1651)

* [R-package] removed horizontal whitespace (fixes #1642)

* [R-package] fixed missing newline in test file
parent f44b60b6
......@@ -19,7 +19,7 @@ lgb.train(params = list(), data, nrounds = 10, valids = list(),
\item{valids}{a list of \code{lgb.Dataset} objects, used for validation}
\item{obj}{objective function, can be character or custom objective function. Examples include
\item{obj}{objective function, can be character or custom objective function. Examples include
\code{regression}, \code{regression_l1}, \code{huber},
\code{binary}, \code{lambdarank}, \code{multiclass}, \code{multiclass}}
......@@ -55,10 +55,10 @@ List of callback functions that are applied at each iteration.}
\itemize{
\item{boosting}{Boosting type. \code{"gbdt"} or \code{"dart"}}
\item{num_leaves}{number of leaves in one tree. defaults to 127}
\item{max_depth}{Limit the max depth for tree model. This is used to deal with
\item{max_depth}{Limit the max depth for tree model. This is used to deal with
overfit when #data is small. Tree still grow by leaf-wise.}
\item{num_threads}{Number of threads for LightGBM. For the best speed, set this to
the number of real CPU cores, not the number of threads (most
the number of real CPU cores, not the number of threads (most
CPU using hyper-threading to generate 2 threads per CPU core).}
}}
}
......
......@@ -41,21 +41,21 @@ List of callback functions that are applied at each iteration.}
\item{...}{Additional arguments passed to \code{\link{lgb.train}}. For example
\itemize{
\item{valids}{a list of \code{lgb.Dataset} objects, used for validation}
\item{obj}{objective function, can be character or custom objective function. Examples include
\item{obj}{objective function, can be character or custom objective function. Examples include
\code{regression}, \code{regression_l1}, \code{huber},
\code{binary}, \code{lambdarank}, \code{multiclass}, \code{multiclass}}
\item{eval}{evaluation function, can be (a list of) character or custom eval function}
\item{record}{Boolean, TRUE will record iteration message to \code{booster$record_evals}}
\item{colnames}{feature names, if not null, will use this to overwrite the names in dataset}
\item{categorical_feature}{list of str or int. type int represents index, type str represents feature names}
\item{reset_data}{Boolean, setting it to TRUE (not the default value) will transform the booster model
\item{reset_data}{Boolean, setting it to TRUE (not the default value) will transform the booster model
into a predictor model which frees up memory and the original datasets}
\item{boosting}{Boosting type. \code{"gbdt"} or \code{"dart"}}
\item{num_leaves}{number of leaves in one tree. defaults to 127}
\item{max_depth}{Limit the max depth for tree model. This is used to deal with
\item{max_depth}{Limit the max depth for tree model. This is used to deal with
overfit when #data is small. Tree still grow by leaf-wise.}
\item{num_threads}{Number of threads for LightGBM. For the best speed, set this to
the number of real CPU cores, not the number of threads (most
the number of real CPU cores, not the number of threads (most
CPU using hyper-threading to generate 2 threads per CPU core).}
}}
}
......
......@@ -10,9 +10,9 @@ if (.Machine$sizeof.pointer != 8){
R_int_UUID <- .Internal(internalsID())
R_ver <- as.double(R.Version()$major) + as.double(R.Version()$minor)/10
if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
if (!(R_int_UUID == "0310d4b8-ccb1-4bb8-ba94-d36a55f60262"
|| R_int_UUID == "2fdf6c18-697a-4ba7-b8ef-11c0d92f1327")){
print("Warning: unmatched R_INTERNALS_UUID, may cannot run normally.")
print("Warning: unmatched R_INTERNALS_UUID, may cannot run normally.")
}
# Move in CMakeLists.txt
......@@ -26,17 +26,17 @@ if (!use_precompile) {
# Check repository content
source_dir <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
setwd(source_dir)
# Prepare building package
build_dir <- file.path(source_dir, "build", fsep = "/")
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)
# Prepare installation steps
cmake_cmd <- "cmake "
build_cmd <- "make _lightgbm"
lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/")
if (use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=ON ")
}
......@@ -76,12 +76,12 @@ if (!use_precompile) {
}
}
}
# Install
system(paste0(cmake_cmd, " .."))
system(build_cmd)
src <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/")
} else {
# Has precompiled package
......@@ -89,11 +89,11 @@ if (!use_precompile) {
if (file.exists(file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/"))) {
src <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/")
} else if (file.exists(file.path(lib_folder, paste0("Release/lib_lightgbm", SHLIB_EXT), fsep = "/"))) {
src <- file.path(lib_folder, paste0("Release/lib_lightgbm", SHLIB_EXT), fsep = "/")
src <- file.path(lib_folder, paste0("Release/lib_lightgbm", SHLIB_EXT), fsep = "/")
} else {
src <- file.path(lib_folder, paste0("/windows/x64/DLL/lib_lightgbm", SHLIB_EXT), fsep = "/") # Expected result: installation will fail if it is not here or any other
}
}
# Check installation correctness
......
......@@ -10,10 +10,10 @@ test_label <- agaricus.test$label[1:100]
test_that("lgb.Dataset: basic construction, saving, loading", {
# from sparse matrix
dtest1 <- lgb.Dataset(test_data, label=test_label)
# from dense matrix
# from dense matrix
dtest2 <- lgb.Dataset(as.matrix(test_data), label=test_label)
expect_equal(getinfo(dtest1, 'label'), getinfo(dtest2, 'label'))
# save to a local file
tmp_file <- tempfile('lgb.Dataset_')
lgb.Dataset.save(dtest1, tmp_file)
......@@ -27,14 +27,14 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
test_that("lgb.Dataset: getinfo & setinfo", {
dtest <- lgb.Dataset(test_data)
dtest$construct()
setinfo(dtest, 'label', test_label)
labels <- getinfo(dtest, 'label')
expect_equal(test_label, getinfo(dtest, 'label'))
expect_true(length(getinfo(dtest, 'weight')) == 0)
expect_true(length(getinfo(dtest, 'init_score')) == 0)
# any other label should error
expect_error(setinfo(dtest, 'asdf', test_label))
})
......
......@@ -7,7 +7,7 @@ test_that("Feature penalties work properly", {
# Fit a series of models with varying penalty on most important variable
var_name <- "odor=none"
var_index <- which(train$data@Dimnames[[2]] == var_name)
bst <- lapply(seq(1, 0, by = -0.1), function(x) {
feature_penalties <- rep(1, ncol(train$data))
feature_penalties[var_index] <- x
......@@ -16,27 +16,27 @@ test_that("Feature penalties work properly", {
label = train$label,
num_leaves = 5,
learning_rate = 0.05,
nrounds = 20,
objective = "binary",
nrounds = 20,
objective = "binary",
feature_penalty = paste0(feature_penalties, collapse = ","),
metric="binary_error",
verbose = -1
)
})
var_gain <- lapply(bst, function(x) lgb.importance(x)[Feature == var_name, Gain])
var_cover <- lapply(bst, function(x) lgb.importance(x)[Feature == var_name, Cover])
var_freq <- lapply(bst, function(x) lgb.importance(x)[Feature == var_name, Frequency])
# Ensure that feature gain, cover, and frequency decreases with stronger penalties
expect_true(all(diff(unlist(var_gain)) <= 0))
expect_true(all(diff(unlist(var_cover)) <= 0))
expect_true(all(diff(unlist(var_freq)) <= 0))
expect_lt(min(diff(unlist(var_gain))), 0)
expect_lt(min(diff(unlist(var_cover))), 0)
expect_lt(min(diff(unlist(var_freq))), 0)
# Ensure that feature is not used when feature_penalty = 0
expect_length(var_gain[[length(var_gain)]], 0)
})
\ No newline at end of file
})
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