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_breakdown for linear model with splines #31

Closed
rdenham opened this issue Jul 10, 2018 · 2 comments
Closed

prediction_breakdown for linear model with splines #31

rdenham opened this issue Jul 10, 2018 · 2 comments

Comments

@rdenham
Copy link

rdenham commented Jul 10, 2018

Hi,
just wondering how easy it would be to allow prediction_breakdown to work with a linear model when you use a spline term in the predictor. Here is my example:

apart.lm <- lm(m2.price ~ ns(construction.year, df=5) + surface + floor + no.rooms + district,
               data=apartments)
aplm.ex <- explain(apart.lm, data=apartmentsTest[, 2:6], y = apartmentsTest$m2.price)
new_apartment <- apartmentsTest[1,]
aplm.bd <- prediction_breakdown(aplm.ex, observation=new_apartment)

Gives the error:

Error in `[.data.frame`(new_observation, colnames(ny)) : 
  undefined columns selected

I guess I could take the ns part out and use the generated basis function, but it would be convenient if you didn't have to do this, particularly if you wanted to compare, eg, models with different basis functions.

Robert

@pbiecek
Copy link
Member

pbiecek commented Jul 10, 2018

Thanks,
It is a general issue how to handle variable transformations specified in the model formula
In the first step I will add support for the recipe package, as it allows for tracking of variable preprocessing steps.
Currently the dirty trick would be to call model.matrix directly to generate a data with new variables, but I will work on something more convenient.

@pbiecek
Copy link
Member

pbiecek commented Feb 18, 2020

should work after changes in iBreakDown v 1.0

@pbiecek pbiecek closed this as completed Feb 18, 2020
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