0

I'm trying to calculate the prediction of a model on a dataset but I get an error with the model generated by the library caret model <- caret::train(method="gamSpline", ...)

> model$modelInfo$label
[1] "Generalized Additive Model using Splines"
> model$modelInfo$library
[1] "gam"


> pred <- predict(object = model, newdata = newData)

Error

 Error in s(V1, df = 3) : could not find function "s" 

12. eval(predvars, data, env) 
11. eval(predvars, data, env) 
10. model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) 
9. model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels) 
8. predict.lm(object, newdata, se.fit, scale = 1, type = ifelse(type == 
    "link", "response", type), terms = terms, na.action = na.action) 
7. predict.glm(object, newdata, type = local.type, dispersion = dispersion, 
    se.fit = FALSE, terms = terms) 
6. newdata.predict.Gam(object, newdata, type, dispersion, se.fit, 
    na.action, terms, ...) 
5. gam:::predict.Gam(modelFit, newdata, type = "response") at gamSpline.R#42
4. method$predict(modelFit = modelFit, newdata = newdata, submodels = param) 
3. predictionFunction(method = object$modelInfo, modelFit = object$finalModel, 
    newdata = newdata, preProc = object$preProcess) 
2. predict.train(object = model, newdata = newData) 
1. predict(object = model, newdata = newData) 

My newData look like this dim(newData): 101 513

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
problème0123
  • 841
  • 2
  • 9
  • 23
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Pictures of data are not very helpful because we can't copy/paste the data. – MrFlick Aug 29 '19 at 19:31
  • 2
    `library(gam)` ? – Ben Bolker Aug 29 '19 at 19:40
  • Hello, Sorry for the non-replication, actually it makes a library(gam) I don't understand I thought when doing library(caret) it was going to load the libraries, the installation must have gone wrong. – problème0123 Aug 29 '19 at 20:44

0 Answers0