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

Add get_random_subset poc utility function #1928

Merged
merged 14 commits into from Apr 30, 2024
Merged

Conversation

R-Palazzo
Copy link
Contributor

CU-86azvqpqe
Resolve #1877

A few considerations regarding this PR:
1 - NaNs handling: Currently, I don't drop NaN foreign keys
2 - Randomness: For reproducibility, I set a seed, is it fine?
3 - Index: Should we reset the index of the tables at the end after all the dropping is done? This is also a question for drop_unknown_references.
4 - Verbosity: To be consistent with the other POC methods, I added a verbose parameter to simplify_schema()
5 - Disconnected schema: Subsampling disconnected schema should work with get_random_subset. I wrote down a test where I mocked the metadata validation since disconnected schemas are not supported there.

Thanks for your review and your thoughts on this ;)

@R-Palazzo R-Palazzo requested a review from a team as a code owner April 18, 2024 12:52
@sdv-team
Copy link
Contributor

@R-Palazzo R-Palazzo removed the request for review from a team April 18, 2024 12:53
sdv/multi_table/utils.py Outdated Show resolved Hide resolved
sdv/multi_table/utils.py Outdated Show resolved Hide resolved
sdv/multi_table/utils.py Outdated Show resolved Hide resolved
sdv/utils/poc.py Outdated Show resolved Hide resolved
@frances-h
Copy link
Contributor

@R-Palazzo just to respond to some of your considerations:

1 - NaNs handling: Currently, I don't drop NaN foreign keys

I think it might make more sense to treat NaNs similarly to how we do with drop_unknown_references and add a flag to indicate if we should drop them or not. As an added consideration, if we don't drop them, maybe should we update the functionality to drop a proportional number of NaN foreign keys to keep the table balanced?

2 - Randomness: For reproducibility, I set a seed, is it fine?

I'm actually not sure we want a fixed seed here, since it might be helpful to re-run the function to get a different subsample. Maybe instead we could control the randomness in a similar way to how we control it when we sample from synthesizers?

3 - Index: Should we reset the index of the tables at the end after all the dropping is done? This is also a question for drop_unknown_references.

In my opinion, I think we can leave the index as-is. We don't use the index, and users might want to be able to compare the subsampled tables back to their original data.

4 - Verbosity: To be consistent with the other POC methods, I added a verbose parameter to simplify_schema()

Nice, I think this works well :)

Copy link
Contributor

@amontanez24 amontanez24 left a comment

Choose a reason for hiding this comment

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

Should we try to align this more with the strategy used in the database subsampling? They seem pretty different at the moment

return ancestors


def _get_disconnected_roots_from_table(relationship, table):
Copy link
Contributor

Choose a reason for hiding this comment

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

should be relationships

Parent table to subsample.
parent_primary_key (str):
Name of the primary key of the parent table.
pk_referenced_before_parent (set):
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: could we move parent to the front? ie. parent_pks_referenced_before.

from sdv.multi_table import HMASynthesizer
from sdv.multi_table.hma import MAX_NUMBER_OF_COLUMNS

MODELABLE_SDTYPE = ['categorical', 'numerical', 'datetime', 'boolean']
RANDOM_STATE = 42
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we should control randomness for this

@R-Palazzo R-Palazzo force-pushed the issue-1877-random-subset branch 2 times, most recently from a1e0bcb to b93e71d Compare April 26, 2024 17:19
tests/unit/multi_table/test_utils.py Outdated Show resolved Hide resolved
sdv/multi_table/utils.py Outdated Show resolved Hide resolved
sdv/multi_table/utils.py Outdated Show resolved Hide resolved
@R-Palazzo R-Palazzo merged commit 060bae9 into main Apr 30, 2024
37 checks passed
@R-Palazzo R-Palazzo deleted the issue-1877-random-subset branch April 30, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add get_random_subset poc utility function
5 participants