tidyverse / modelr

Helper functions for modelling
https://modelr.tidyverse.org
GNU General Public License v3.0
401 stars 66 forks source link

Enable custom model objects in add_predictions #114

Closed LukasTang closed 10 months ago

LukasTang commented 3 years ago

Hi,

I have custom model objects, that I define, for example, as follows:

setClass("custommodel",slots=list(coef="numeric"))

setMethod("predict", "custommodel",function(object,newdata){ newdata$pred<-object@coef return(list(fit=newdata$pred))})

model<-new("custommodel",coef=3)

But then I cannot apply:

df%>%add_predictions(model)

Because it says "no applicable method predict for object pf class custommodel"

I believe that the namespace for predict is defined to be from the stats package, could it be possible to make the function more flexible? Or is it already possible?

Reproducible example:

library(tidyverse)
setClass("custommodel",slots=list(coef="numeric"))

setMethod("predict", "custommodel",function(object,newdata){
newdata$pred<-object@coef
return(list(fit=newdata$pred))})

model<-new("custommodel",coef=3)

df<-data.frame(a=123)
df%>%add_predictions(model)
hadley commented 10 months ago

modelr is now superseded, which means that we'll only perform critical bug fixes needed to keep it on CRAN. Thanks for contributing this idea and my apologies that it took so long to inform you that this package is no longer under development.