-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ENH] Adding FunctionTransformer #1498
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this looks great!
If we didn't already have this (and I indeed can't find it), would be a nice thing to have!
Some requests for change:
- the one failure seems to be related to the example in the docstring, number of spaces
custom
is not very descriptive as a module name, why notfunctiontrafo
or similar?
Thanks for the feedback! Couldn't find something like this neither. How do you like the filename Not sure which error you are referring to wrt docstrings. Should I remove some spaces after the 0. in the array? |
Yes, that's clear and concise imo. |
looks like you changed the module name but forgot to change an import of it somewhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's failing again with the docstring...
I think the number of spaces in the docstring example and in the actual printout need to be exactly the same, or the test won't be happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Parameters | ||
---------- | ||
Z : pd.Series / pd.DataFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you accept pd.Series / pd.DataFrame
, so we should do the same for fit()
@boukepostma would you mind to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a useful way to create an arbitrary series-to-series transformer. I've got 2 quick comments.
The first is a small change I'd like to see to make it more readable when people go back and look at the code later.
self.inverse_transform
is callingself._transform
.
I get that the call in the inverse_transform is applying the inverse function. But it seems unintuitive at first glance to see self._transform
being applied in self.inverse_transform
. I'd suggest renaming the existing self._transform
to a helper function like "apply_function". Then you could use the helper function as appropriate in self._transform
and separately in a self._inverse_transform
. Then you could call self._inverse_transform
in self.inverse_transform
.
Second comment is more of a general question. Elsewhere in sktime we have functions to create different estimators. Do we want this as a class or is this a case where the class is not part of the public API, but a function like make_series_transformer
is part of the API and returns the constructed class? @mloning, @aiwalter and @fkiraly I'm interested to your thoughts hear when it makes sense to do that.
@RNKuhns, I think this very much makes sense as part of the public API, a general-purpose transformer creator. |
Hi all, thanks a lot for the feedback! I hope to have time later this week to go implement the suggested changes :) |
FunctionTransformer should work for any Serie or Dataframe (i.e. Panel and Series). To which category should I add it in the documentation and folder structure? |
I pushed some changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can go in for the current release, any changes tbd separately.
Reference Issues/PRs
What does this implement/fix? Explain your changes.
Adds an sktime-compatible adjustment of sklearn's FunctionTransformer. This class allows the user to easily create custom transformers that are different from the ones already included in sktime (e.g. SqrtTransformer, ExponentTransformer).
Does your contribution introduce a new dependency? If yes, which one?
No
What should a reviewer concentrate their feedback on?
def _check_inverse_transform()
: this works but there may be more reliable ways to check whetherfunc
andinverse_func
are the inverse. Note: comparing with==
does not work due to numeric errors.Any other comments?
Looking forward to receiving your feedback!
PR checklist
For all contributions
For new estimators