Skip to content

Commit

Permalink
Merge pull request #2591 from moj-analytical-services/add_modify_sett…
Browse files Browse the repository at this point in the history
…ings_example_to_cookbook

add modify settings exampel to cookbook
  • Loading branch information
RobinL authored Jan 20, 2025
2 parents 851b73e + 7ddaaff commit 471f1ed
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/demos/examples/duckdb/cookbook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,57 @@
"first_unique_id = df.iloc[0].unique_id\n",
"linker.evaluation.labelling_tool_for_specific_record(unique_id=first_unique_id, overwrite=True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Modifying settings after loading from a serialised `.json` model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import splink.comparison_library as cl\n",
"from splink import DuckDBAPI, Linker, SettingsCreator, block_on, splink_datasets\n",
"\n",
"# setup to create a model\n",
"\n",
"db_api = DuckDBAPI()\n",
"\n",
"df = splink_datasets.fake_1000\n",
"\n",
"settings = SettingsCreator(\n",
" link_type=\"dedupe_only\",\n",
" comparisons=[\n",
" cl.LevenshteinAtThresholds(\"first_name\"),\n",
" cl.LevenshteinAtThresholds(\"surname\"),\n",
"\n",
" ],\n",
" blocking_rules_to_generate_predictions=[\n",
" block_on(\"first_name\", \"dob\"),\n",
" block_on(\"surname\"),\n",
" ]\n",
")\n",
"\n",
"linker = Linker(df, settings, db_api)\n",
"\n",
"\n",
"linker.misc.save_model_to_json(\"mod.json\", overwrite=True)\n",
"\n",
"new_settings = SettingsCreator.from_path_or_dict(\"mod.json\")\n",
"\n",
"new_settings.retain_intermediate_calculation_columns = True\n",
"new_settings.blocking_rules_to_generate_predictions = [\"1=1\"]\n",
"new_settings.additional_columns_to_retain = [\"cluster\"]\n",
"\n",
"linker = Linker(df, new_settings, DuckDBAPI())\n",
"\n",
"linker.inference.predict().as_duckdbpyrelation().show()"
]
}
],
"metadata": {
Expand Down

0 comments on commit 471f1ed

Please sign in to comment.