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

Create sample_conditions() method #691

Closed
npatki opened this issue Jan 27, 2022 · 0 comments
Closed

Create sample_conditions() method #691

npatki opened this issue Jan 27, 2022 · 0 comments
Assignees
Labels
data:single-table Related to tabular datasets feature request Request for a new feature
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented Jan 27, 2022

Problem Description

Let's make sampling more user friendly. We can create multiple methods for different user needs.

A new sample_conditions method can address conditional sampling needs.

Expected behavior

Parameters:

  • (required) conditions : A list of Condition objects (see Create Condition object #689) -- this specifies num_rows
  • max_tries: renamed from existing max_retries param (default: 100)
  • batch_size_per_try: Number of rows to sample per try (default: 10x requested num)
  • randomize_samples will determine whether or not there should be a fixed seed (default: True)
# works with any tabular model
from sdv.tabular import CTGAN
model = CTGAN()
model.fit(data)

# see Issue #689 for Condition object details
from sdv.tabular.sampling import Conditions
female_users = Condition(column_values={'sex': 'F', 'active_user': True}, num_rows=50)
inactive_users = Condition(column_values={'active_user': False}, num_rows=100)
conditions = [female_users, inactive_users]

# pass in list of conditions
model.sample_conditions(conditions, max_retries=200, randomize_sample=False)

Error Handling

Running out of tries

# Always gracefully reject sample (ie return any rows that are sampled)
>>> synthetic_data = model.sample_conditions(conditions)
Warning: Only able to sample 75 rows for the given conditions. To sample more rows, try increasing max_tries
(currently: 100) or increasing batch_size_per_try (currently: 10000). Note that increasing these values will also
increase the sampling time.

# Error if we weren't able to sample any rows
>>> synthetic_data = model.sample_conditions(conditions)
Error: Unable to sample any rows for the given conditions. Try increasing max_tries
(currently: 100) or increasing batch_size_per_try (currently: 10000). Note that increasing these values will also
increase the sampling time.

Checking for invalid input

# Unexpected column name
>>> c = Condition(column_values={'New_Column': 42})
>>> synthetic_data = model.sample_conditions([c])
Error: Unexpected column name 'New_Column'. Use a column name that was present in the original data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:single-table Related to tabular datasets feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants