egenn / rtemis

Advanced Machine Learning and Visualization
https://rtemis.org
GNU General Public License v3.0
140 stars 19 forks source link

Trying to predict with a bag model produces NA #15

Closed BillPetti closed 5 years ago

BillPetti commented 5 years ago

I am trying to use the result of a bag model fit to predict on new data. When I use predict I am getting NAs as the predicted value. Here's a reproducible example:

parkinsons <- read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/parkinsons/parkinsons.data")

parkinsons$Status <- factor(parkinsons$status, levels = c(1, 0))
parkinsons$status <- NULL
parkinsons$name <- NULL

res <- resample(parkinsons, seed = 2019)
park.train <- parkinsons[res$Subsample_1, ]
park.test <- parkinsons[-res$Subsample_1, ]

test_bag <- bag(park.train, 
                park.test, 
                mod = 'cart', 
                k = 10, 
                mod.params = list(maxdepth = 1), 
                .resample = rtset.resample(resampler = 'bootstrap', 
                                           n.resamples = 20))

predict(test_bag, park.test)

   1    6   13   14   18   29   31   32   37   38   42   44   49   53   54   56   57   58   61 
<NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 
  63   72   77   80   81   83   88   92   95  101  103  104  106  119  122  126  127  131  135 
<NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 
 142  148  149  150  154  163  168  176  182  190  195 
<NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 
Levels: 1 0

I see the same behavior on other data.

egenn commented 5 years ago

Thank you - I will look into this later tonight and get back to you!

egenn commented 5 years ago

Hi @BillPetti, I pushed a fix - will do more testing. Thanks again