[R-package] store numeric attributes with higher precision (#1628)

This commit is contained in:
Vadim Khotilovich
2016-10-03 13:01:17 -05:00
committed by Tianqi Chen
parent 1673bcbe7e
commit f9648ac320
2 changed files with 23 additions and 2 deletions

View File

@@ -73,6 +73,19 @@ test_that("xgb-attribute functionality", {
expect_null(xgb.attributes(bst))
})
test_that("xgb-attribute numeric precision", {
# check that lossless conversion works with 17 digits
# numeric -> character -> numeric
X <- 10^runif(100, -20, 20)
X2X <- as.numeric(format(X, digits = 17))
expect_identical(X, X2X)
# retrieved attributes to be the same as written
for (x in X) {
xgb.attr(bst.Tree, "x") <- x
expect_identical(as.numeric(xgb.attr(bst.Tree, "x")), x)
}
})
test_that("xgb.model.dt.tree works with and without feature names", {
names.dt.trees <- c("Tree", "Node", "ID", "Feature", "Split", "Yes", "No", "Missing", "Quality", "Cover")
dt.tree <- xgb.model.dt.tree(feature_names = feature.names, model = bst.Tree)