Skip to content
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

[GSProcessing] Add saving and re-applying for numerical transforms. #1085

Merged
merged 6 commits into from
Nov 14, 2024

Conversation

thvasilo
Copy link
Contributor

@thvasilo thvasilo commented Nov 8, 2024

Issue #, if available:

Fixes #985

Description of changes:

  • We introduce saving and re-applying numerical transformations for all transforms except rank-gauss, which by definition cannot be reapplied.
  • For the more complex transformations we re-construct the original PySpark transformer objects, by retaining the values needed for each transformation (e.g. the min and max values), creating tiny DFs that only contain those numbers and re-training the transformer on that tiny dataset. Then we can apply the trained transformer to the desired data and we get the same result.
  • To reduce code duplication we pull out the core computations for standard and min-max normalization into their own functions (_apply_standard_transform, _apply_minmax_transform), which we can call from both the original transformation and the re-applied one. The presence or absence of pre-computed statistics in the function call determines which code path we follow.
  • We modify the apply_imputation and apply_norm functions to also return the representation along with the transformed DF. We encapsulate the return values in their own dataclass (ImputationResult, NormalizationResult), to make future modifications easier (by not requiring to change the function's return type).
  • Introduce new tests to check all re-construction cases.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@thvasilo thvasilo added ready able to trigger the CI gsprocessing For issues and PRs related the the GSProcessing library 0.4 labels Nov 8, 2024
@thvasilo thvasilo added this to the 0.4 release milestone Nov 8, 2024
@thvasilo thvasilo self-assigned this Nov 8, 2024
@thvasilo thvasilo changed the title [GSProcessing] Add transformation saving and re-applying for numerical transforms. [GSProcessing] Add saving and re-applying for numerical transforms. Nov 8, 2024
Copy link
Contributor

@classicsong classicsong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add .. versionadded:: 0.4.0 or .. versionchanged:: 0.4.0 for new and updated APIs.

Copy link
Collaborator

@jalencato jalencato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…ns/dist_transformations/dist_numerical_transformation.py

Co-authored-by: xiang song(charlie.song) <[email protected]>
@thvasilo
Copy link
Contributor Author

Please add .. versionadded:: 0.4.0 or .. versionchanged:: 0.4.0 for new and updated APIs.

None of the APIs changed are exposed to users @classicsong do we want to track all internal changes?

@classicsong
Copy link
Contributor

Please add .. versionadded:: 0.4.0 or .. versionchanged:: 0.4.0 for new and updated APIs.

None of the APIs changed are exposed to users @classicsong do we want to track all internal changes?

No.

Copy link
Contributor

@classicsong classicsong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thvasilo thvasilo merged commit d0873f1 into awslabs:main Nov 14, 2024
3 checks passed
@thvasilo thvasilo deleted the gsp-numerical-reapply branch November 14, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.4 gsprocessing For issues and PRs related the the GSProcessing library ready able to trigger the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GSProcessing] Support loading existing feature transform rules for floating point features.
3 participants