Search code examples
rr-caretnls

How to use stats::nls non-linear least squares regression in caret?


I'm comparing a bunch of Machine Learning models on a dataset I have. The current model in production is a equation of the form:

y ~ a + b * x1^c * x2^d * x3^e,

Since I'd like to use the current situation as a benchmark to asses the improvement I'd get from other models, I've implemented it in R using:

powerModel <- nls(y ~ a + b * x1^c * x2^d * x3^e, 
                  data = df,
                  start = list(a = 0, b = 1, c = 1, d = 1, e = 0),
                  model=T)

This works fine, however I train my other models using cross-validation using the Caret package. I'd like to perform the same cross-validation on the nls model. However, I find nothing on how to use a custom formula in Caret. So my question is: how do I use a custom formulate or the nls model in Caret cross-validation training?


Solution

  • The instructions to make a custom method are here.