topepo/caret

Error in train(x, y, "nb", trControl = trainControl(method = "cv", number = 10)) : could not find function "train"

Opened this issue · 0 comments

If you are making a feature request or starting a discussion, you can ignore everything below and go wild =D However, please request new models using the project page.

If you are filing a bug, make sure these boxes are checked before submitting your issue— thank you!

  • Start a new R session
  • Install the latest version of caret: update.packages(oldPkgs="caret", ask=FALSE)
  • Write a minimal reproducible example
  • Do not use parallel processing in the code (unless you are certain that the issue is about parallel processing).
  • run sessionInfo()

Minimal, reproducible example:

Please read this page: reprex = {repr}oducible {ex}ample; your issue can be easily formatted using the reprex package.

Text and example code modified from the R FAQ on stackoverflow

Minimal dataset:

library(caret)
set.seed(1)
dat <- twoClassSim(100)
X <- dat[,1:5]
y <- dat[["Class"]]

If you have some data that would be too difficult to construct using caret::twoClassSim or caret::SLC14_1, then you can always make a subset of your original data, using e.g. head(), subset() or the indices. Then use e.g. dput() to give us something that can be put in R immediately, e.g. dput(head(iris,4))

If you must use dput(head()), please first remove an columns from your dataset that are not necessary to reproduce the error.

If your data frame has a factor with many levels, the dput output can be unwieldy because it will still list all the possible factor levels even if they aren't present in the the subset of your data. To solve this issue, you can use the droplevels() function. Notice below how species is a factor with only one level: dput(droplevels(head(iris, 4)))

Minimal, runnable code:

model_class <- train(
  X, y, 
  metric='ROC',
  trControl=trainControl(
    method="cv", 
    number=5,
    classProbs=TRUE, 
    summaryFunction=twoClassSummary,
    savePredictions="final")
)
print(model_class)

Session Info:

>sessionInfo()

You can delete the text in each section that explains how to do it correctly.
Be sure to test your 2 chunks of code in an empty R session before submitting your issue!