topepo / caret

caret (Classification And Regression Training) R package that contains misc functions for training and plotting classification and regression models
http://topepo.github.io/caret/index.html
1.61k stars 634 forks source link

feature request: support for classprobs with bstSm #1321

Open crossxwill opened 1 year ago

crossxwill commented 1 year ago

The method bstSm does not appear to support classProbs=TRUE. I'm requesting that the method support probability predictions. Here's a reprex that shows the error when class probabilities are requested for bstSm.

library(caret)

## data

set.seed(1)

x <- rnorm(1000)

z <- -2 + 2*x + rnorm(1000)

y <- rbinom(1000, 1, boot::inv.logit(z))

df <- data.frame(y=y, x=x)

summary(df)

## response

df$label <- factor(ifelse(df$y == 1, "yes", "no"),
                   levels=c("yes","no"))

summary(df)

## control

fcstHorizon <- 100
initWindow <- 800
param_skip <- fcstHorizon - 1

fitControl_oneSE <- trainControl(method = "timeslice",
                                 initialWindow=initWindow,
                                 horizon=fcstHorizon,
                                 fixedWindow=FALSE,
                                 skip=param_skip,
                                 ## Estimate class probabilities
                                 classProbs = TRUE,
                                 ## Evaluate performance using 
                                 ## the following function
                                 summaryFunction = mnLogLoss,
                                 selectionFunction="oneSE")

## gamboost

set.seed(1)

gam_mod <- train(
  label ~ x,
  data = df,
  method = "gamboost",
  trControl = fitControl_oneSE,
  metric = "logLoss",
  dfbase =3
)

plot(gam_mod)

## bstSm (errors out)

set.seed(1)

bst_mod <- train(
  label ~ x,
  data = df,
  method = "bstSm",
  trControl = fitControl_oneSE,
  metric = "logLoss"
)

plot(bst_mod)