Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
46d29e8a
Unverified
Commit
46d29e8a
authored
Dec 07, 2021
by
James Lamb
Committed by
GitHub
Dec 07, 2021
Browse files
[R-package] remove Dataset `getinfo()` (#4864)
* [R-package] remove Dataset getinfo() * fix docs
parent
a91e4b2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
150 deletions
+2
-150
R-package/NAMESPACE
R-package/NAMESPACE
+0
-2
R-package/R/lgb.Dataset.R
R-package/R/lgb.Dataset.R
+0
-77
R-package/man/getinfo.Rd
R-package/man/getinfo.Rd
+0
-52
R-package/tests/testthat/test_dataset.R
R-package/tests/testthat/test_dataset.R
+2
-19
No files found.
R-package/NAMESPACE
View file @
46d29e8a
...
...
@@ -4,14 +4,12 @@ S3method("dimnames<-",lgb.Dataset)
S3method(dim,lgb.Dataset)
S3method(dimnames,lgb.Dataset)
S3method(get_field,lgb.Dataset)
S3method(getinfo,lgb.Dataset)
S3method(predict,lgb.Booster)
S3method(print,lgb.Booster)
S3method(set_field,lgb.Dataset)
S3method(slice,lgb.Dataset)
S3method(summary,lgb.Booster)
export(get_field)
export(getinfo)
export(lgb.Dataset)
export(lgb.Dataset.construct)
export(lgb.Dataset.create.valid)
...
...
R-package/R/lgb.Dataset.R
View file @
46d29e8a
...
...
@@ -464,18 +464,6 @@ Dataset <- R6::R6Class(
},
getinfo
=
function
(
name
)
{
warning
(
paste0
(
"Dataset$getinfo() is deprecated and will be removed in a future release. "
,
"Use Dataset$get_field() instead."
))
return
(
self
$
get_field
(
field_name
=
name
)
)
},
get_field
=
function
(
field_name
)
{
# Check if attribute key is in the known attribute list
...
...
@@ -1157,71 +1145,6 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {
}
#' @name getinfo
#' @title Get information of an \code{lgb.Dataset} object
#' @description Get one attribute of a \code{lgb.Dataset}
#' @param dataset Object of class \code{lgb.Dataset}
#' @param name the name of the information field to get (see details)
#' @param ... other parameters (ignored)
#' @return info data
#'
#' @details
#' The \code{name} field can be one of the following:
#'
#' \itemize{
#' \item \code{label}: label lightgbm learn from ;
#' \item \code{weight}: to do a weight rescale ;
#' \item{\code{group}: used for learning-to-rank tasks. An integer vector describing how to
#' group rows together as ordered results from the same set of candidate results to be ranked.
#' For example, if you have a 100-document dataset with \code{group = c(10, 20, 40, 10, 10, 10)},
#' that means that you have 6 groups, where the first 10 records are in the first group,
#' records 11-30 are in the second group, etc.}
#' \item \code{init_score}: initial score is the base prediction lightgbm will boost from.
#' }
#'
#' @examples
#' \donttest{
#' data(agaricus.train, package = "lightgbm")
#' train <- agaricus.train
#' dtrain <- lgb.Dataset(train$data, label = train$label)
#' lgb.Dataset.construct(dtrain)
#'
#' labels <- lightgbm::getinfo(dtrain, "label")
#' lightgbm::set_field(dtrain, "label", 1 - labels)
#'
#' labels2 <- lightgbm::getinfo(dtrain, "label")
#' stopifnot(all(labels2 == 1 - labels))
#' }
#' @export
getinfo
<-
function
(
dataset
,
...
)
{
UseMethod
(
"getinfo"
)
}
#' @rdname getinfo
#' @export
getinfo.lgb.Dataset
<-
function
(
dataset
,
name
,
...
)
{
warning
(
"Calling getinfo() on a lgb.Dataset is deprecated. Use get_field() instead."
)
additional_args
<-
list
(
...
)
if
(
length
(
additional_args
)
>
0L
)
{
warning
(
paste0
(
"getinfo.lgb.Dataset: Found the following passed through '...': "
,
paste
(
names
(
additional_args
),
collapse
=
", "
)
,
". These are ignored. In future releases of lightgbm, this warning will become an error. "
,
"See ?getinfo.lgb.Dataset for documentation on how to call this function."
))
}
if
(
!
lgb.is.Dataset
(
x
=
dataset
))
{
stop
(
"getinfo.lgb.Dataset: input dataset should be an lgb.Dataset object"
)
}
return
(
dataset
$
get_field
(
field_name
=
name
))
}
#' @name get_field
#' @title Get one attribute of a \code{lgb.Dataset}
#' @description Get one attribute of a \code{lgb.Dataset}
...
...
R-package/man/getinfo.Rd
deleted
100644 → 0
View file @
a91e4b2d
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.Dataset.R
\name{getinfo}
\alias{getinfo}
\alias{getinfo.lgb.Dataset}
\title{Get information of an \code{lgb.Dataset} object}
\usage{
getinfo(dataset, ...)
\method{getinfo}{lgb.Dataset}(dataset, name, ...)
}
\arguments{
\item{dataset}{Object of class \code{lgb.Dataset}}
\item{...}{other parameters (ignored)}
\item{name}{the name of the information field to get (see details)}
}
\value{
info data
}
\description{
Get one attribute of a \code{lgb.Dataset}
}
\details{
The \code{name} field can be one of the following:
\itemize{
\item \code{label}: label lightgbm learn from ;
\item \code{weight}: to do a weight rescale ;
\item{\code{group}: used for learning-to-rank tasks. An integer vector describing how to
group rows together as ordered results from the same set of candidate results to be ranked.
For example, if you have a 100-document dataset with \code{group = c(10, 20, 40, 10, 10, 10)},
that means that you have 6 groups, where the first 10 records are in the first group,
records 11-30 are in the second group, etc.}
\item \code{init_score}: initial score is the base prediction lightgbm will boost from.
}
}
\examples{
\donttest{
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
lgb.Dataset.construct(dtrain)
labels <- lightgbm::getinfo(dtrain, "label")
lightgbm::set_field(dtrain, "label", 1 - labels)
labels2 <- lightgbm::getinfo(dtrain, "label")
stopifnot(all(labels2 == 1 - labels))
}
}
R-package/tests/testthat/test_dataset.R
View file @
46d29e8a
...
...
@@ -13,7 +13,6 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
dtest1
<-
lgb.Dataset
(
test_data
,
label
=
test_label
)
# from dense matrix
dtest2
<-
lgb.Dataset
(
as.matrix
(
test_data
),
label
=
test_label
)
expect_equal
(
getinfo
(
dtest1
,
"label"
),
getinfo
(
dtest2
,
"label"
))
expect_equal
(
get_field
(
dtest1
,
"label"
),
get_field
(
dtest2
,
"label"
))
# save to a local file
...
...
@@ -23,25 +22,9 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
dtest3
<-
lgb.Dataset
(
tmp_file
)
lgb.Dataset.construct
(
dtest3
)
unlink
(
tmp_file
)
expect_equal
(
getinfo
(
dtest1
,
"label"
),
getinfo
(
dtest3
,
"label"
))
expect_equal
(
get_field
(
dtest1
,
"label"
),
get_field
(
dtest3
,
"label"
))
})
test_that
(
"lgb.Dataset: getinfo"
,
{
dtest
<-
lgb.Dataset
(
test_data
)
dtest
$
construct
()
set_field
(
dtest
,
"label"
,
test_label
)
labels
<-
getinfo
(
dtest
,
"label"
)
expect_equal
(
test_label
,
getinfo
(
dtest
,
"label"
))
expect_true
(
length
(
getinfo
(
dtest
,
"weight"
))
==
0L
)
expect_true
(
length
(
getinfo
(
dtest
,
"init_score"
))
==
0L
)
# any other label should error
expect_error
(
set_field
(
dtest
,
"asdf"
,
test_label
))
})
test_that
(
"lgb.Dataset: get_field & set_field"
,
{
dtest
<-
lgb.Dataset
(
test_data
)
dtest
$
construct
()
...
...
@@ -91,8 +74,8 @@ test_that("Dataset$slice() supports passing Dataset attributes through '...'", {
,
init_score
=
init_score
)
dsub1
$
construct
()
expect_null
(
dtest
$
get
info
(
"init_score"
),
NULL
)
expect_identical
(
dsub1
$
get
info
(
"init_score"
),
init_score
)
expect_null
(
dtest
$
get
_field
(
"init_score"
),
NULL
)
expect_identical
(
dsub1
$
get
_field
(
"init_score"
),
init_score
)
})
test_that
(
"Dataset$set_reference() on a constructed Dataset fails if raw data has been freed"
,
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment