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

Fix bug with labelling tool where it didn't work offline #1646

Merged

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Oct 11, 2023

Type of PR

  • BUG
  • FEAT
  • MAINT
  • DOC

Closes #1645

Give a brief description for the solution you have provided

Updates consistent with #1639 to make sure it works offline

Here's a script to produce a tool to ensure it works offline

script to test
import duckdb
import pandas as pd

import splink.duckdb.duckdb_comparison_library as cl
from splink.duckdb.duckdb_linker import DuckDBLinker

df = pd.read_parquet(
    "https://github.com/moj-analytical-services/splink_demos/raw/master/data/historical_figures_with_errors_50k.parquet"
)

# df = pd.read_parquet("synthetic_50k_clean.parquet")
# df["postcode_fake"] = df["postcode"]
ids = list(df["unique_id"].sample(1))
# ids.append("Q52155443-1")

# ids = ["Q52155443-1"]

settings = {
    "probability_two_random_records_match": 0.01,
    "link_type": "dedupe_only",
    "blocking_rules_to_generate_predictions": [
        "l.first_name = r.first_name",
        "l.surname = r.surname",
    ],
    "comparisons": [
        cl.jaro_winkler_at_thresholds(
            "first_name", [0.9, 0.7], term_frequency_adjustments=True
        ),
        cl.jaro_winkler_at_thresholds(
            "surname", [0.9, 0.7], term_frequency_adjustments=True
        ),
        cl.levenshtein_at_thresholds("dob", [1, 2], term_frequency_adjustments=True),
        cl.levenshtein_at_thresholds(
            "postcode_fake", 2, term_frequency_adjustments=True
        ),
        cl.exact_match("birth_place", term_frequency_adjustments=True),
        cl.exact_match("occupation", term_frequency_adjustments=True),
    ],
    "retain_matching_columns": True,
    "retain_intermediate_calculation_columns": True,
    "max_iterations": 2,
    "em_convergence": 0.01,
}


linker = DuckDBLinker(df, settings)


linker.estimate_probability_two_random_records_match(
    [
        "l.first_name = r.first_name and l.surname = r.surname and l.dob = r.dob",
        "substr(l.first_name,1,2) = substr(r.first_name,1,2) and l.surname = r.surname and substr(l.postcode_fake,1,2) = substr(r.postcode_fake,1,2)",
        "l.dob = r.dob and l.postcode_fake = r.postcode_fake",
    ],
    recall=0.6,
)

linker.estimate_u_using_random_sampling(target_rows=1e5)

for this_id in ids:
    linker.labelling_tool_for_specific_record(
        this_id,
        out_path=f"try_labels/labelling_tool_dedupe_only.html",
        show_splink_predictions_in_interface=True,
        view_in_jupyter=False,
        overwrite=True,
        match_weight_threshold=-10,
    )

@RobinL RobinL linked an issue Oct 11, 2023 that may be closed by this pull request
2 tasks
@RobinL RobinL changed the title works Fix bug with labelling tool where it didn't work offline Oct 11, 2023
Copy link
Contributor

@ADBond ADBond left a comment

Choose a reason for hiding this comment

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

Great, this works perfectly 👍

@RobinL
Copy link
Member Author

RobinL commented Oct 18, 2023

Thanks!

@RobinL RobinL merged commit 6cea199 into master Oct 18, 2023
8 checks passed
@RobinL RobinL deleted the 1645-the-labelling-tool-does-not-work-offline-as-intended branch October 18, 2023 08:34
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.

The Labelling tool does not work offline as intended
2 participants