Repository navigation
Add PolynomialTransformer - #81
Conversation
|
On another note, the logic for actually generating column combinations in InteractionTransformers uses Combinatorics.jl. I couldn't see similar functionality there to generate complete lists of monomials so had to add custom code for that. It's possible the new code could also be used to get rid of Combinatorics.jl altogether, but I haven't done that here. |
|
@olivierlabayle Are you willing and able to provide a review here, in the next 3-4 weeks, say? This PR makes a replacement for your InteractionTransformer, as set out in the referenced issue. |
|
@ablaom Yes thank you, please assign me and I'll review! |
|
Thank you very much. |
olivierlabayle
left a comment
There was a problem hiding this comment.
This looks good to me, two little caveats:
- You forgot to include the new test file in
runtests.jl - The "combination with replacement" exists in
Combinatorics.jl. Since theMLJTransformsalready depends on it, it might be worth outsourcing the algorithm to them.
| interactions_only=false, | ||
| ) | ||
| model = PolynomialTransformer(degree, features, interactions_only) | ||
| message = MMI.clean!(model) |
There was a problem hiding this comment.
why not throwing here?
There was a problem hiding this comment.
clean! mutates the model parameter so that it is valid, so no need to throw an exception. Or am I missing the point of your question?
There was a problem hiding this comment.
I suppose I am wondering whether it would be better to explicitly throw if a user's code does not make sense rather than assuming a fallback to order=2?
| using Dates: DateTime, Date, Time, Day, Hour | ||
| _get(x) = CategoricalArrays.DataAPI.unwrap(x) | ||
|
|
||
| include("test_utils.jl") |
There was a problem hiding this comment.
You probably want to include the new include("transformers/other_transformers/polynomial_transformer.jl")
| # # CORE IMPLEMENTATION | ||
|
|
||
| function MMI.transform(model::PolynomialTransformer, _, X) | ||
| features = MLJTransforms.actualfeatures(model.features, X) |
There was a problem hiding this comment.
any reason to keep the MLJTransforms prefix here and line 142?
There was a problem hiding this comment.
Not necessary but helpful for maintenance: The method actualfeaures, while not defined in the current file, is defined in MLJTransforms somewhere, and not from the namespace of some other package. At least, this is helpful to me.
| premonomials(alphabet, degree, ::WithoutRepetitions) = | ||
| premonomials(alphabet, degree, Combinatorics.combinations) | ||
| premonomials(alphabet, degree, ::WithRepetitions) = | ||
| premonomials(alphabet, degree, orderedwords) |
There was a problem hiding this comment.
Your implementation seems to produce the same results but this is also defined in Combinatorics: Combinatorics.with_replacement_combinations or am I mistaken? At least the tests also pass with this function.
There was a problem hiding this comment.
Ah - I completely missed this, thank you. In eeab9bf I've swapped this in and dumped my orderedwords method.
Co-authored-by: Olivier Labayle <48188914+olivierlabayle@users.noreply.github.com>
olivierlabayle
left a comment
There was a problem hiding this comment.
Thank you @ablaom , all good for me, I'll let you make the call on the clean! vs throw as it is rather a design choice.
|
@olivierlabayle Thanks for your prompt review. As indicated, I adopted all your suggestions. Maintaining the quality of the MLJ ecosystem depends crucially on volunteer PR reviews such as this one. ❤️ |
This PR addresses #45 .
InteractionTransformer(; kwargs...)is now equivalent to*PolynomialTransformer(; interactions_only=true, kwargs...)but usingInteractionTranformertriggers a depwarn.I've renamed the field
ordertodegree(seems more usual for a polynomial) butorderis retained as a kwarg, aliased todegree.Here's an example drawn from the new doc string:
An additional change: Somewhat confusingly, we had and an empty src/utils.jl but test/utils.jl defines only functions needed to run tests (dataset generators). I moved some code shared by both
InteractionTransformerandPolynomialTransformerto src/utils.jl and moved the contents of test/utils.jl to a new file test/test_utils.jl so I could add actual tests of src/utils.jl in test/utils.jl.*This is not quite true. InteractionTransformer always returns a NamedTuple of Vectors. PolynomialTransformer tries to return a table of the same type as the input table, using Tables.materalizer(input_table).