Isaiah
Isaiah

Reputation: 63

R Crashes when training using caret and method = gamLoess

When I run the code below, R crashes. If I comment out the tuneGrid line in the call to train, there is no crash. I've tried this with another dataset, and still crash R. Crash message is R Session Aborted R encountered a fatal error The session was terminated Start new session.

The code is:

library(splines)
library(foreach)
library(gam)
library(lattice)
library(ggplot2)
library(caret)

# crashes when I uncomment the tuneGrid = tuneGrid line

Set_seed_seed <- 100
data_set <- diamonds[, c(1, 5, 6, 7, 8, 9, 10)]
data_set <- data_set[1:1000,]
formula <- price ~ carat + depth + table + x + y + z
training_control <- trainControl(method = "cv", allowParallel = FALSE)
tune_grid <- expand.grid(span = seq(0.1, 0.9, length = 9), degree = seq(1, 2, length = 2))
set.seed(Set_seed_seed)
GAM_model <- train(formula,
                  data = data_set,
                  method = "gamLoess", 
                  tuneGrid = tune_grid,
                  trControl = training_control
               )

This occurred in R3.2.1 and 3.2.2 using R Studio.

In R gui, also get crashes.

Upvotes: 1

Views: 1559

Answers (2)

topepo
topepo

Reputation: 14316

It is a bug in the gam package. I alerted Trevor Hastie on March 3, 2014 about it:

 library(gam)
 set.seed(1)
 x <- rnorm(1000)
 y <- x^2+0.1*rnorm(1000)
 tdat <- data.frame(y = y, x = x)

 m1 <- gam(y ~ lo(x, span = .5, degree = 2), data = tdat)

That works fine but as I fit multiple models a seg fault occurs (but only with loess and degree = 2).

This will produce it for me:

 for(i in 1:10) m1 <- gam(y ~ lo(x, span = .5, degree = 2), data = tdat)

Upvotes: 2

nathanesau
nathanesau

Reputation: 1721

I verified that the problem exists. I debugged the program and found that the program gets stuck as shown. This is a bug with the foreach package

train(formula, data=data_set, ...) 
    useMethod("train") # train(); namespace:caret
        train(x, y, weight = w, ...) train.formula(); # namespace:caret
            useMethod("train") # train(); namespace:caret
                nominalTrainWorkflow(x = x, ...) # train.default(); namespace:caret  
                    result <- foreach(iter = , ...) # nominalTrainWorkflow(); namespace:caret
                        e <- getDoSeq() # %op%; namespace:foreach
                            list(fun = doSeq, data=NULL) # getDoSeq(); namespace:foreach
                                e$fun(obj, substitute(ex), parent.frame(), e$data) # %op%; namespace:foreach
                                    tryCatch(accumulator(list(r), i) # e$fun; namespace:foreach

Upvotes: 1

Related Questions