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

NaN trained values can break predict() #2334

Open
ADBond opened this issue Aug 14, 2024 · 1 comment
Open

NaN trained values can break predict() #2334

ADBond opened this issue Aug 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ADBond
Copy link
Contributor

ADBond commented Aug 14, 2024

You can train values so that an m-value ends up with a value of NaN. This then breaks the SQL that is generated in .predict().

Here is a non-elegant reprex, very similar to #2333 (although note that we add in slightly fewer values to our new column compared to there):

import splink.comparison_library as cl
from splink import DuckDBAPI, Linker, SettingsCreator, block_on, splink_datasets

settings = SettingsCreator(
    "dedupe_only",
    comparisons=[
        cl.LevenshteinAtThresholds("first_name"),
        cl.LevenshteinAtThresholds("surname"),
        cl.ExactMatch("city"),
        cl.LevenshteinAtThresholds("dob"),
        cl.LevenshteinAtThresholds("email"),
        cl.ExactMatch("cluster"),
        cl.ExactMatch("cluster_1"),
        cl.ExactMatch("cluster_2"),
        cl.ExactMatch("cluster_3"),
        cl.ExactMatch("non_match_cat"),
    ],
    blocking_rules_to_generate_predictions=[
        block_on("dob"),
        block_on("city"),
    ]
)

df = splink_datasets.fake_1000
df["cluster_1"] = df["cluster"]
df["cluster_2"] = df["cluster"]
df["cluster_3"] = df["cluster"]

# specially chosen non-matchy things
df["non_match_cat"] = None
# we add fewer values than in issue #2333
cats = {
    263: 6,
    273: 6,
    500: 7,
    729: 7,
}
for id_n, cat in cats.items():
    df["non_match_cat"][df["unique_id"] == id_n] = cat

db_api = DuckDBAPI()
linker = Linker(df, settings, db_api)

linker.training.estimate_probability_two_random_records_match(
    block_on("first_name", "surname", "dob"), recall=0.7
)
linker.training.estimate_u_using_random_sampling(max_pairs=1e8)

linker.training.estimate_parameters_using_expectation_maximisation(block_on("cluster"))
linker.training.estimate_parameters_using_expectation_maximisation(block_on("dob"))
linker.training.estimate_parameters_using_expectation_maximisation(block_on("city"))

linker.misc.save_model_to_json("nan-model.json", overwrite=True)

linker.inference.predict()

We get an error Referenced column "nan" not found in FROM clause! or similar, much as in #852.

@ADBond ADBond added the bug Something isn't working label Aug 14, 2024
@ADBond
Copy link
Contributor Author

ADBond commented Aug 14, 2024

In fact we can of course push this error to trigger in training by replacing linker.inference.predict() in the example above with linker.training.estimate_parameters_using_expectation_maximisation(block_on("email")).

@lamaeldo - possibly related to the issue in your comment on the above-mentioned issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant