Skip to content
Back to skills

R Ml Boosting

ASecurity

R gradient boosting packages. Use for xgboost, lightgbm, gbm, and catboost.

  • 5 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added June 4, 2026
datagonodeapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-ml-boosting --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Ml Boosting?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Ml Boosting
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-ml-boosting/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-ml-boosting)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-ml-boosting
description: R gradient boosting packages. Use for xgboost, lightgbm, gbm, and catboost.
---

# R Gradient Boosting

High-performance gradient boosting models.

## xgboost

```r
library(xgboost)

# Prepare data
dtrain <- xgb.DMatrix(data = as.matrix(train_x), label = train_y)
dtest <- xgb.DMatrix(data = as.matrix(test_x), label = test_y)

# Parameters
params <- list(
  objective = "binary:logistic",  # or "reg:squarederror"
  eval_metric = "auc",
  max_depth = 6,
  eta = 0.1,
  subsample = 0.8,
  colsample_bytree = 0.8
)

# Train with early stopping
watchlist <- list(train = dtrain, test = dtest)
model <- xgb.train(
  params = params,
  data = dtrain,
  nrounds = 1000,
  watchlist = watchlist,
  early_stopping_rounds = 50,
  verbose = 1
)

# Predictions
pred <- predict(model, dtest)

# Feature importance
importance <- xgb.importance(model = model)
xgb.plot.importance(importance, top_n = 20)

# Cross-validation
cv <- xgb.cv(
  params = params,
  data = dtrain,
  nrounds = 1000,
  nfold = 5,
  early_stopping_rounds = 50
)

# Save/load model
xgb.save(model, "model.xgb")
model <- xgb.load("model.xgb")
```

## lightgbm

```r
library(lightgbm)

# Prepare data
dtrain <- lgb.Dataset(data = as.matrix(train_x), label = train_y)
dtest <- lgb.Dataset(data = as.matrix(test_x), label = test_y, reference = dtrain)

# Parameters
params <- list(
  objective = "binary",
  metric = "auc",
  num_leaves = 31,
  learning_rate = 0.1,
  feature_fraction = 0.8,
  bagging_fraction = 0.8,
  bagging_freq = 5
)

# Train
model <- lgb.train(
  params = params,
  data = dtrain,
  nrounds = 1000,
  valids = list(test = dtest),
  early_stopping_rounds = 50
)

# Predictions
pred <- predict(model, as.matrix(test_x))

# Feature importance
importance <- lgb.importance(model)
lgb.plot.importance(importance, top_n = 20)

# Save/load
lgb.save(model, "model.lgb")
model <- lgb.load("model.lgb")
```

## gbm

```r
library(gbm)

# Train
model <- gbm(
  target ~ .,
  data = train,
  distribution = "bernoulli",  # or "gaussian"
  n.trees = 1000,
  interaction.depth = 4,
  shrinkage = 0.01,
  n.minobsinnode = 10,
  cv.folds = 5
)

# Optimal trees
best_iter <- gbm.perf(model, method = "cv")

# Predictions
pred <- predict(model, test, n.trees = best_iter, type = "response")

# Variable importance
summary(model, n.trees = best_iter)
```

## Hyperparameter Tuning

```r
# xgboost with tidymodels
library(tidymodels)

xgb_spec <- boost_tree(
  trees = 1000,
  tree_depth = tune(),
  min_n = tune(),
  loss_reduction = tune(),
  sample_size = tune(),
  mtry = tune(),
  learn_rate = tune()
) %>%
  set_engine("xgboost") %>%
  set_mode("classification")

xgb_grid <- grid_latin_hypercube(
  tree_depth(),
  min_n(),
  loss_reduction(),
  sample_size = sample_prop(),
  finalize(mtry(), train),
  learn_rate(),
  size = 30
)

tune_results <- tune_grid(
  workflow() %>% add_model(xgb_spec) %>% add_formula(target ~ .),
  resamples = vfold_cv(train, v = 5),
  grid = xgb_grid,
  metrics = metric_set(roc_auc)
)
```

## Comparison

| Package | Speed | Memory | Features |
|---------|-------|--------|----------|
| xgboost | Fast | Medium | GPU, sparse |
| lightgbm | Fastest | Low | Categorical |
| gbm | Slow | High | Simple API |
| catboost | Fast | Medium | Categorical |

Files in this skill

  • SKILL.md3.2 KB
  • lightgbm/SKILL.md3.2 KB
  • xgboost/SKILL.md3.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.