Unverified Commit 9478e52f authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] fix R examples and lgb.plot.interpretation() (#3002)



* [R-package] fix R examples and lgb.plot.interpretation

* remove space in gitignore

* try data.table from conda-forge

* update FAQ
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
parent 0d3e2046
......@@ -406,6 +406,14 @@ lightgbm_r/*
lightgbm*.tar.gz
lightgbm.Rcheck/
# Files created by R examples and tests
**/lgb-Dataset.data
**/lgb-model.rds
**/lgb.Dataset.data
**/model.rds
**/model.txt
**/lgb-model.txt
# Files from interactive R sessions
.Rproj.user
**/.Rhistory
......
......@@ -41,4 +41,4 @@ Imports:
utils
SystemRequirements:
C++11
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
......@@ -845,7 +845,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) {
#' , learning_rate = 1.0
#' , early_stopping_rounds = 5L
#' )
#' lgb.save(model, "model.txt")
#' lgb.save(model, "lgb-model.txt")
#' }
#' @export
lgb.save <- function(booster, filename, num_iteration = NULL) {
......
......@@ -1073,8 +1073,8 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) {
#' data(agaricus.train, package = "lightgbm")
#' train <- agaricus.train
#' dtrain <- lgb.Dataset(train$data, label = train$label)
#' lgb.Dataset.save(dtrain, "lgb.Dataset.data")
#' dtrain <- lgb.Dataset("lgb.Dataset.data")
#' lgb.Dataset.save(dtrain, "lgb-Dataset.data")
#' dtrain <- lgb.Dataset("lgb-Dataset.data")
#' lgb.Dataset.set.categorical(dtrain, 1L:2L)
#'
#' @rdname lgb.Dataset.set.categorical
......
......@@ -49,7 +49,7 @@
#' )
#' lgb.plot.interpretation(
#' tree_interpretation_dt = tree_interpretation[[1L]]
#' , top_n = 5L
#' , top_n = 3L
#' )
#' }
#' @importFrom data.table setnames
......@@ -141,7 +141,7 @@ multiple.tree.plot.interpretation <- function(tree_interpretation,
}
# create plot
tree_interpretation[Contribution > 0.0, bar_color := "firebrick"]
tree_interpretation[abs(Contribution) > 0.0, bar_color := "firebrick"]
tree_interpretation[Contribution == 0.0, bar_color := "steelblue"]
tree_interpretation[.N:1L,
graphics::barplot(
......
......@@ -36,9 +36,13 @@
#' data(iris) # Erase iris dataset
#'
#' # We remapped values differently
#' personal_rules <- list(Species = c("setosa" = 3L,
#' "versicolor" = 2L,
#' "virginica" = 1L))
#' personal_rules <- list(
#' Species = c(
#' "setosa" = 3L
#' , "versicolor" = 2L
#' , "virginica" = 1L
#' )
#' )
#' newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules)
#' str(newest_iris$data) # SUCCESS!
#'
......
......@@ -37,7 +37,7 @@
#' , learning_rate = 1.0
#' , early_stopping_rounds = 5L
#' )
#' saveRDS.lgb.Booster(model, "model.rds")
#' saveRDS.lgb.Booster(model, "lgb-model.rds")
#' }
#' @export
saveRDS.lgb.Booster <- function(object,
......
......@@ -4,8 +4,10 @@
\name{agaricus.test}
\alias{agaricus.test}
\title{Test part from Mushroom Data Set}
\format{A list containing a label vector, and a dgCMatrix object with 1611
rows and 126 variables}
\format{
A list containing a label vector, and a dgCMatrix object with 1611
rows and 126 variables
}
\usage{
data(agaricus.test)
}
......
......@@ -4,8 +4,10 @@
\name{agaricus.train}
\alias{agaricus.train}
\title{Training part from Mushroom Data Set}
\format{A list containing a label vector, and a dgCMatrix object with 6513
rows and 127 variables}
\format{
A list containing a label vector, and a dgCMatrix object with 6513
rows and 127 variables
}
\usage{
data(agaricus.train)
}
......
......@@ -4,7 +4,9 @@
\name{bank}
\alias{bank}
\title{Bank Marketing Data Set}
\format{A data.table with 4521 rows and 17 variables}
\format{
A data.table with 4521 rows and 17 variables
}
\usage{
data(bank)
}
......
......@@ -24,8 +24,8 @@ Set the categorical features of an \code{lgb.Dataset} object. Use this function
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
lgb.Dataset.save(dtrain, "lgb.Dataset.data")
dtrain <- lgb.Dataset("lgb.Dataset.data")
lgb.Dataset.save(dtrain, "lgb-Dataset.data")
dtrain <- lgb.Dataset("lgb-Dataset.data")
lgb.Dataset.set.categorical(dtrain, 1L:2L)
}
......@@ -68,7 +68,7 @@ tree_interpretation <- lgb.interprete(
)
lgb.plot.interpretation(
tree_interpretation_dt = tree_interpretation[[1L]]
, top_n = 5L
, top_n = 3L
)
}
}
......@@ -48,9 +48,13 @@ all.equal(new_iris$data, newer_iris$data)
data(iris) # Erase iris dataset
# We remapped values differently
personal_rules <- list(Species = c("setosa" = 3L,
"versicolor" = 2L,
"virginica" = 1L))
personal_rules <- list(
Species = c(
"setosa" = 3L
, "versicolor" = 2L
, "virginica" = 1L
)
)
newest_iris <- lgb.prepare_rules(data = iris, rules = personal_rules)
str(newest_iris$data) # SUCCESS!
......
......@@ -39,6 +39,6 @@ model <- lgb.train(
, learning_rate = 1.0
, early_stopping_rounds = 5L
)
lgb.save(model, "model.txt")
lgb.save(model, "lgb-model.txt")
}
}
......@@ -61,6 +61,6 @@ model <- lgb.train(
, learning_rate = 1.0
, early_stopping_rounds = 5L
)
saveRDS.lgb.Booster(model, "model.rds")
saveRDS.lgb.Booster(model, "lgb-model.rds")
}
}
......@@ -211,7 +211,7 @@ This is a known bug: `Microsoft/LightGBM#539 <https://github.com/microsoft/Light
3. ``error in data.table::data.table()...argument 2 is NULL``
-------------------------------------------------------------
If you experiencing this error when running `lightgbm`, you may be facing the same issue reported in `#2715 <https://github.com/microsoft/LightGBM/issues/2715>`_. If you use ``lgb.dl()`` to build from source (i.e. not using pre-compiled dll), you need to upgrade your version of ``data.table`` to at least version 1.12.0.
If you are experiencing this error when running ``lightgbm``, you may be facing the same issue reported in `#2715 <https://github.com/microsoft/LightGBM/issues/2715>`_ and later in `#2989 <https://github.com/microsoft/LightGBM/pull/2989#issuecomment-614374151>`_. We have seen that some in some situations, using ``data.table`` 1.11.x results in this error. To get around this, you can upgrade your version of ``data.table`` to at least version 1.12.0.
------
......
......@@ -227,13 +227,13 @@ def generate_r_docs(app):
/home/docs/.conda/bin/conda create -q -y -n r_env \
r-base=3.5.1=h1e0a451_2 \
r-devtools=1.13.6=r351h6115d3f_0 \
r-data.table=1.11.4=r351h96ca727_0 \
r-jsonlite=1.5=r351h96ca727_0 \
r-matrix=1.2_14=r351h96ca727_0 \
r-testthat=2.0.0=r351h29659fb_0 \
cmake=3.14.0=h52cb24c_0 \
ca-certificates=2019.11.27=0
/home/docs/.conda/bin/conda install -q -y -n r_env -c conda-forge \
r-data.table=1.12.8=r35hcdcec82_0 \
r-pkgdown=1.3.0=r35h6115d3f_1001 \
r-roxygen2=6.1.1=r35h0357c0b_1001
source /home/docs/.conda/bin/activate r_env
......
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