scikit-lego
scikit-lego copied to clipboard
feat: `RepeatingBasisFunction.inverse_transform`
Description
This PR implements get_feature_names_out()
for _RepeatingBasisFunction
, and RepeatingBasisFunction
(which inherits feature names from the former).
This PR also implements an inverse_transform for _RepeatingBasisFunction
in passing. I did not include a more general implementation for RepeatingBasisFunction
(as the one I use requires importing pandas), but the inverse_transform() can be accessed from the fitted transformer via .pipeline_.named_transformers_['repeatingbasis'].inverse_transform()
). It's a rare use case, but it shouldn't affect other uses in any way, so I figured I'd include it. Note that the transformation is only invertible if the original values are in the input_range (upper bound excluded). Otherwise, the reconstructed values are only equal modulo the width of the range.
Two tests have been added to test_repeatingbasisfunction.py:
- test that set_output(transform='pandas') works properly with
RepeatingBasisFunction
- test that the new
inverse_transform()
for_RepeatingBasisFunction
truly recovers the original values (as long as they fall within the input_range).
Note that for feature names, ClassNamePrefixFeaturesOutMixin could also be used if self.n_periods
was renamed to self._n_features_out
, but I didn't see a simple way of keeping the original column name as prefix, so I adopted a solution perhaps more idiosyncratic.
It's a minor PR overall, so I didn't ping before submitting. I hope it's okay.
Progress on Issue #543
Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist:
- [X] My code follows the style guidelines (ruff)
- [X] I have commented my code, particularly in hard-to-understand areas
- [X] I have made corresponding changes to the documentation (also to the readme.md)
- [X] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added tests to check whether the new feature adheres to the sklearn convention
- [X] New and existing unit tests pass locally with my changes
If you feel your PR is ready for a review, ping @FBruzzesi or @koaning.