tidymodels / TMwR

Code and content for "Tidy Modeling with R"
https://tmwr.org
Other
579 stars 272 forks source link

Update 14-iterative-search.Rmd #367

Closed matanhakim closed 1 year ago

matanhakim commented 1 year ago

Fix typo

juliasilge commented 1 year ago

Thanks for this fix @matanhakim! I'll need to go in and see what needs to be updated for DALEX separately.

topepo commented 1 year ago

The issue is related to creating the natural spline terms for a single observation.

bake_step_ns() correctly makes the new terms from the single data

Browse[2]> new_values
           1            2            3            4            5            6 
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 
           7            8            9           10           11           12 
0.000000e+00 3.390881e-05 3.057544e-01 6.496525e-01 4.455920e-02 0.000000e+00 
          13           14           15           16           17           18 
0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 
          19           20 
0.000000e+00 0.000000e+00 
attr(,"class")
[1] "ns"     "basis"  "matrix"
attr(,"degree")
[1] 3
attr(,"knots")
 [1] 41.99479 42.01414 42.01775 42.01956 42.02209 42.02518 42.02822 42.03110
 [9] 42.03250 42.03461 42.03593 42.03842 42.04288 42.04646 42.04991 42.05229
[17] 42.05518 42.05889 42.06127
attr(,"Boundary.knots")
[1] 41.98650 42.06339
attr(,"intercept")
[1] FALSE

The next line renames the columns using names0(num, prefix) but fails because, for some reason, the new value doesn't have column dimensions:

Browse[2]> is.matrix(new_values)
[1] FALSE
Browse[2]> # but.... 
Browse[2]> class(new_values)
[1] "ns"     "basis"  "matrix"
Browse[2]> ncol(new_values)
NULL
Browse[2]> length(new_values)
[1] 20

¯_(ツ)_/¯

I'll make an issue in recipes to fix this.

We should transition the code here to use step_spline_natural(), but it has the same issue.

topepo commented 1 year ago

There is a new recipes version on CRAN that fixes this issue.

github-actions[bot] commented 12 months ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.