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

Iterative categorical matching #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Hussein-Mahfouz
Copy link
Collaborator

As described in #13

@Hussein-Mahfouz Hussein-Mahfouz linked an issue Oct 15, 2024 that may be closed by this pull request
@sgreenbury
Copy link
Collaborator

sgreenbury commented Oct 18, 2024

Adding notes from discussion to check and implement, then can merge (happy to do both these):

  • Confirm we can run for the whole population
  • Add config table matching: for columns to include optional matching and a value for n_matches (if not passed, no threshold)

@Hussein-Mahfouz
Copy link
Collaborator Author

The new iterative_match_categorical function does not need to be iterative. We can run an exact match on specified column as shown in the last commit. We do the following:

  • add all columns to required_columns
  • keep optional_cols empty - that means we will only have one iteration see here
  • make n_matches = 0
# Define required columns for matching
required_columns_fixed = [
    "number_adults",
    "number_children",
    "number_cars",
    "num_pension_age",
    "rural_urban_2_categories",
]

# Define optional columns in order of importance (most to least important)
optional_columns_fixed = []

# # Match using iterative matching
matcher_fixed = MatcherExact(
    df_pop=spc_matching,
    df_pop_id="hid",
    df_sample=nts_matching,
    df_sample_id="HouseholdID",
    matching_dict = matching_dfs_dict,
    fixed_cols=required_columns_fixed,
    optional_cols=optional_columns_fixed,
    n_matches=0,  
    chunk_size=50000,
    show_progress=True,
)

matches_hh_level_fixed = matcher_fixed.iterative_match_categorical()

@sgreenbury
Copy link
Collaborator

sgreenbury commented Oct 18, 2024

  • also add docs in the config toml (base.toml) explaining order is the order in which features are dropped

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.

Improve matching approach
2 participants