0

Th example from the documentation (1) uses a classification example. However, I would need to use regression. How can I do regression adaptive boosting in R?

This code results in the following error:

> mybag <- boosting(totalUSD ~ ., data = df.train, boos = T)
Error in predict.rpart(fit, newdata = data[, -1], type = "class") : 
  Invalid prediction for "rpart" object

Here is an example of my data:

structure(list(totalUSD = c(9726.6, 730.14, 750, 200, 60.49, 
310.81, 151.23, 145.5, 3588.13, 400), durationDays = c(730, 724, 
730, 189, 364, 364, 364, 176, 730, 1095), familySize = c(4, 1, 
2, 1, 3, 2, 1, 1, 4, 4), serviceName = c("Service5", 
"Service6", "Service9", "Service4", 
"Service1", "Service2", "Service1", "Service3", 
"Service7", "Service8"), homeLocationGeoLat = c(37.09024, 
10.691803, 37.09024, 35.86166, 55.378051, 35.86166, 51.165691, 
-30.559482, -30.559482, 41.87194), homeLocationGeoLng = c(-95.712891, 
-61.222503, -95.712891, 104.195397, -3.435973, 104.195397, 10.451526, 
22.937506, 22.937506, 12.56738), hostLocationGeoLat = c(55.378051, 
37.09024, 55.378051, 55.378051, 37.09024, 1.352083, 55.378051, 
37.09024, 23.424076, 1.352083), hostLocationGeoLng = c(-3.435973, 
-95.712891, -3.435973, -3.435973, -95.712891, 103.819836, -3.435973, 
-95.712891, 53.847818, 103.819836), geoDistance = c(6838055.10555534, 
4532586.82063172, 6838055.10555534, 7788275.0443749, 6838055.10555534, 
3841784.48282769, 1034141.95021832, 14414898.8246973, 6856033.00945242, 
10022083.1525388)), .Names = c("totalUSD", "durationDays", "familySize", 
"serviceName", "homeLocationGeoLat", "homeLocationGeoLng", "hostLocationGeoLat", 
"hostLocationGeoLng", "geoDistance"), row.names = c(25601L, 6083L, 
24220L, 20235L, 8372L, 456L, 8733L, 27257L, 15928L, 24099L), class = "data.frame")
  1. http://www.rdocumentation.org/packages/adabag/functions/adabag-package
user1477388
  • 20,790
  • 32
  • 144
  • 264
  • 1
    The documentation seems to suggest that the package is specific to classification. – Lars Kotthoff Aug 11 '15 at 19:55
  • @LarsKotthoff Do you know of anyway to perform regression boosting in R without using this package, then? I haven't been able to find any simple examples. – user1477388 Aug 11 '15 at 20:32
  • mlr has interfaces to a few packages that allow gradient boosting, see [the list of supported learners](https://mlr-org.github.io/mlr-tutorial/devel/html/integrated_learners/index.html). – Lars Kotthoff Aug 11 '15 at 20:35
  • Thanks, Lars. I provided an answer below taken from your suggestion. – user1477388 Aug 11 '15 at 21:25

1 Answers1

0

As suggested by Lars in the comments above, I used mboost which seems to work quite nicely. Providing my answer here for future reference.

library(caret) # required for createDataPartition
#install.packages("party") # required for mboost
#install.packages("mboost") # for blackboost/regression boosting
library(mboost)

# divide data ensuring both partitions have the same factors
trainIndex <- createDataPartition(df$serviceName, p = .8, list = F, times = 2)
df.train <- df[trainIndex,]
df.test <- df[-trainIndex,]

# train model
gb <- blackboost(totalUSD ~ ., data = df.train)

# see predict.mboost for more info...
pred <- predict(gb, df.test)
user1477388
  • 20,790
  • 32
  • 144
  • 264