Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prediction crashes if train inside function and only one predictor #1134

Closed
ran88dom99 opened this issue Apr 9, 2020 · 1 comment
Closed

Comments

@ran88dom99
Copy link

require(caret)
#> Loading required package: caret
#> Loading required package: lattice
#> Loading required package: ggplot2
mdle<-function(daata){
  return(
    train(x = data.frame(daata[,2:length(daata[1,])]),
          y = daata[,1],
          method = "lm",
          tuneLength = 1)
  )
}
bse<-rnorm(100)
d<-data.frame(a=bse,b=bse+rnorm(100))
lmd <- mdle(d[,c(1,2)]) #model with only x
yox = predict(lmd,newdata=d[c(2)]) 
#> Error in eval(predvars, data, env): object 'daata...2.length.daata.1.....' not found

Created on 2020-04-08 by the reprex package (v0.3.0)

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)

@topepo
Copy link
Owner

topepo commented Feb 10, 2021

The problem is in how mdle subsets columns:

Browse[2]> names(data.frame(daata[,2:length(daata[1,])]))
[1] "daata...2.length.daata.1....."

compared with the columns you give to predict():

> names(d[c(2)])
[1] "b"

It is expecting the same name.

@topepo topepo closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants