Booster

library(unifiedml) # this package

 base_learner <- function() {
   Model$new(lm)
 }
 
 boost_model <- BoostingModel$new(
   base_learner_fn = base_learner,
   B = 100,
   eta = 0.1
 )
 
 # Generate sample data
 set.seed(123)
 X <- matrix(rnorm(200), ncol = 4)
 y <- 2*X[,1] - 1.5*X[,2] + rnorm(50)
 
 # Fit and predict
 boost_model$fit(X, y)
## Iteration 10 / 100
## Iteration 20 / 100
## Iteration 30 / 100
## Iteration 40 / 100
## Iteration 50 / 100
## Iteration 60 / 100
## Iteration 70 / 100
## Iteration 80 / 100
## Iteration 90 / 100
## Iteration 100 / 100
 preds <- boost_model$predict(X)
 
 # Get variable importance
 imp <- boost_model$variable_importance()
## 
## Variable Importance
## ===================
##  Feature Importance
##       X1 53.8111025
##       X2 44.6466990
##       X3  0.9816176
##       X4  0.5605810
 print(imp)
##   Feature Importance
## 1      X1 53.8111025
## 2      X2 44.6466990
## 3      X3  0.9816176
## 4      X4  0.5605810
 # Plot loss history
 boost_model$plot_loss()

 # Cross-validation
 cv_scores <- cross_val_score(boost_model, X, y, cv = 5)
##   |                                                                              |                                                                      |   0%  |                                                                              |==============                                                        |  20%  |                                                                              |============================                                          |  40%  |                                                                              |==========================================                            |  60%  |                                                                              |========================================================              |  80%  |                                                                              |======================================================================| 100%