Guest User

Untitled

a guest
Oct 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. # Bug with RStudio + doMC + caret combination
  2. #
  3. # (1) Problem when calling PenalizedLDA
  4. #
  5. # With registerDoMC the libraries called within train() do not get loaded
  6. #
  7. # PenalizedLDA : penalizedLDA and flsa do not get loaded
  8. # LDA : MASS does not get loaded
  9. # nb: klaR does not get loaded
  10. #
  11. # (The libraries are loaded in createModel.R and predictionFunction.R)
  12. #
  13. # This results in an error when calling train
  14. # Error in names(resamples) <- gsub("^\\.", "", names(resamples)) :
  15. # attempt to set an attribute on NULL
  16. # registerDoSEQ does not have this problem
  17. # This problem is unique to RStudio, the default R shell does not have this
  18. # problem
  19.  
  20.  
  21. rm(list=ls(all = TRUE))
  22. library(caret)
  23. library(doMC)
  24.  
  25. registerDoMC()
  26. #registerDoSEQ()
  27.  
  28.  
  29. data(mdrr)
  30. nearZeroVar_classwise <- function(X,y) (unique(unlist(dlply(data.frame(X=X, y=y),.(y),function(Z) nearZeroVar(Z[,1:NCOL(X)])))))
  31. X <- mdrrDescr
  32. y <- mdrrClass
  33. X <- X[,-nearZeroVar_classwise(X,y)]
  34. X <- X[,-findCorrelation(cor(X), cutoff=0.75)]
  35.  
  36.  
  37. # library(klaR)
  38. # detach("package:klaR")
  39. ptm <- proc.time()
  40. (fit <- train(X, y, method="nb", trControl=trainControl(method="boot", number=5)))
  41. print(proc.time() - ptm)
  42.  
  43.  
  44. # library(penalizedLDA)
  45. # library(flsa)
  46. # detach("package:penalizedLDA")
  47. # detach("package:flsa")
  48. ptm <- proc.time()
  49. (fit <- train(X, y, method="lda", trControl=trainControl(method="boot", number=5)))
  50. print(proc.time() - ptm)
  51.  
  52. # library(MASS)
  53. # detach("package:MASS")
  54. ptm <- proc.time()
  55. (fit <- train(X, y, method="PenalizedLDA", trControl=trainControl(method="boot", number=5)))
  56. print(proc.time() - ptm)
Add Comment
Please, Sign In to add comment