Skip to content

FilterFeaturesTransform #271

Closed
1 task
Mr-Geekman opened this issue Nov 12, 2021 · 2 comments 路 Fixed by #277
Closed
1 task

FilterFeaturesTransform #271

Mr-Geekman opened this issue Nov 12, 2021 · 2 comments 路 Fixed by #277
Assignees
Labels
enhancement New feature or request

Comments

@Mr-Geekman
Copy link
Contributor

Mr-Geekman commented Nov 12, 2021

馃殌 Feature Request

Add FilterFeaturesTransform to filter features during transformation.

Motivation

In ensembles we want to include/exclude different features in different models. There is no way to do this on current version of the library.

Proposal

Prototype:

class _OneSegmentFilterFeaturesTransform(Transform):
    def __init__(self, include: Optional[Sequence[str]] = None, exclude: Optional[Sequence[str]] = None):
        self.include = include
        self.exclude = exclude

    def fit(self, *args) -> "_OneSegmentFilterFeaturesTransform":
        return self

    def transform(self, df: pd.DataFrame) -> pd.DataFrame:
        result = df.copy()
        if self.include is not None:
            result = result[self.include]
        if self.exclude is not None:
            result = result.drop(columns=self.exclude)
        return result


class FilterFeaturesTransform(PerSegmentWrapper):
    def __init__(self, include: Optional[Sequence[str]] = None, exclude: Optional[Sequence[str]] = None):
        self.include = include
        self.exclude = exclude

        super().__init__(
            transform=_OneSegmentFilterFeaturesTransform(
                include=self.include,
                exclude=self.exclude,
            )
        )

Test cases

  1. Test that selected on and exactly one option include or exclude.
  2. Test that after transform remains only features in include (test different number of features).
  3. Test that after transform there are all features except for features in exclude (test different number of features).

Alternatives

No response

Additional context

No response

Checklist

  • I discussed this issue with ETNA Team
@Mr-Geekman Mr-Geekman added the enhancement New feature or request label Nov 12, 2021
@Mr-Geekman
Copy link
Contributor Author

It is better to make it without PerSegmentWrapper.

@Mr-Geekman
Copy link
Contributor Author

Add exception on non-existent columns and test for it.

@Mr-Geekman Mr-Geekman self-assigned this Nov 12, 2021
@Mr-Geekman Mr-Geekman changed the title FiltefFeaturesTransform FilterFeaturesTransform Nov 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant