[R] resolve brace_linter warnings (#8564)
This commit is contained in:
parent
40a1a2ffa8
commit
fbe40d00d8
@ -615,9 +615,11 @@ cb.gblinear.history <- function(sparse=FALSE) {
|
|||||||
coefs <- NULL
|
coefs <- NULL
|
||||||
|
|
||||||
init <- function(env) {
|
init <- function(env) {
|
||||||
if (!is.null(env$bst)) { # xgb.train:
|
# xgb.train(): bst will be present
|
||||||
} else if (!is.null(env$bst_folds)) { # xgb.cv:
|
# xgb.cv(): bst_folds will be present
|
||||||
} else stop("Parent frame has neither 'bst' nor 'bst_folds'")
|
if (is.null(env$bst) && is.null(env$bst_folds)) {
|
||||||
|
stop("Parent frame has neither 'bst' nor 'bst_folds'")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert from list to (sparse) matrix
|
# convert from list to (sparse) matrix
|
||||||
|
|||||||
@ -251,8 +251,7 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, params) {
|
|||||||
# Creates CV folds stratified by the values of y.
|
# Creates CV folds stratified by the values of y.
|
||||||
# It was borrowed from caret::createFolds and simplified
|
# It was borrowed from caret::createFolds and simplified
|
||||||
# by always returning an unnamed list of fold indices.
|
# by always returning an unnamed list of fold indices.
|
||||||
xgb.createFolds <- function(y, k = 10)
|
xgb.createFolds <- function(y, k = 10) {
|
||||||
{
|
|
||||||
if (is.numeric(y)) {
|
if (is.numeric(y)) {
|
||||||
## Group the numeric data based on their magnitudes
|
## Group the numeric data based on their magnitudes
|
||||||
## and sample within those groups.
|
## and sample within those groups.
|
||||||
|
|||||||
@ -104,7 +104,11 @@ xgb.importance <- function(feature_names = NULL, model = NULL, trees = NULL,
|
|||||||
XGBoosterFeatureScore_R, model$handle, jsonlite::toJSON(args, auto_unbox = TRUE, null = "null")
|
XGBoosterFeatureScore_R, model$handle, jsonlite::toJSON(args, auto_unbox = TRUE, null = "null")
|
||||||
)
|
)
|
||||||
names(results) <- c("features", "shape", "weight")
|
names(results) <- c("features", "shape", "weight")
|
||||||
n_classes <- if (length(results$shape) == 2) { results$shape[2] } else { 0 }
|
if (length(results$shape) == 2) {
|
||||||
|
n_classes <- results$shape[2]
|
||||||
|
} else {
|
||||||
|
n_classes <- 0
|
||||||
|
}
|
||||||
importance <- if (n_classes == 0) {
|
importance <- if (n_classes == 0) {
|
||||||
data.table(Feature = results$features, Weight = results$weight)[order(-abs(Weight))]
|
data.table(Feature = results$features, Weight = results$weight)[order(-abs(Weight))]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -102,7 +102,9 @@ xgb.plot.importance <- function(importance_matrix = NULL, top_n = NULL, measure
|
|||||||
original_mar <- par()$mar
|
original_mar <- par()$mar
|
||||||
|
|
||||||
# reset margins so this function doesn't have side effects
|
# reset margins so this function doesn't have side effects
|
||||||
on.exit({par(mar = original_mar)})
|
on.exit({
|
||||||
|
par(mar = original_mar)
|
||||||
|
})
|
||||||
|
|
||||||
mar <- original_mar
|
mar <- original_mar
|
||||||
if (!is.null(left_margin))
|
if (!is.null(left_margin))
|
||||||
|
|||||||
@ -12,7 +12,7 @@ cat('running cross validation\n')
|
|||||||
# do cross validation, this will print result out as
|
# do cross validation, this will print result out as
|
||||||
# [iteration] metric_name:mean_value+std_value
|
# [iteration] metric_name:mean_value+std_value
|
||||||
# std_value is standard deviation of the metric
|
# std_value is standard deviation of the metric
|
||||||
xgb.cv(param, dtrain, nrounds, nfold = 5, metrics = {'error'})
|
xgb.cv(param, dtrain, nrounds, nfold = 5, metrics = 'error')
|
||||||
|
|
||||||
cat('running cross validation, disable standard deviation display\n')
|
cat('running cross validation, disable standard deviation display\n')
|
||||||
# do cross validation, this will print result out as
|
# do cross validation, this will print result out as
|
||||||
|
|||||||
@ -170,8 +170,9 @@ test_that("SHAPs sum to predictions, with or without DART", {
|
|||||||
label = y,
|
label = y,
|
||||||
nrounds = nrounds)
|
nrounds = nrounds)
|
||||||
|
|
||||||
pr <- function(...)
|
pr <- function(...) {
|
||||||
predict(fit, newdata = d, ...)
|
predict(fit, newdata = d, ...)
|
||||||
|
}
|
||||||
pred <- pr()
|
pred <- pr()
|
||||||
shap <- pr(predcontrib = TRUE)
|
shap <- pr(predcontrib = TRUE)
|
||||||
shapi <- pr(predinteraction = TRUE)
|
shapi <- pr(predinteraction = TRUE)
|
||||||
|
|||||||
@ -86,7 +86,10 @@ For that purpose, we will:
|
|||||||
|
|
||||||
```{r classToIntegers}
|
```{r classToIntegers}
|
||||||
# Convert from classes to numbers
|
# Convert from classes to numbers
|
||||||
y <- train[, nameLastCol, with = FALSE][[1]] %>% gsub('Class_','',.) %>% {as.integer(.) -1}
|
y <- train[, nameLastCol, with = FALSE][[1]] %>%
|
||||||
|
gsub('Class_','',.) %>%
|
||||||
|
as.integer %>%
|
||||||
|
subtract(., 1)
|
||||||
|
|
||||||
# Display the first 5 levels
|
# Display the first 5 levels
|
||||||
y[1:5]
|
y[1:5]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user