{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading and saving models\n", "\n", "Since data linking tasks can take a long time to execute, it is often useful to be able to save the results. For example, this allows model parameters to be applied to new data, or iterations to be re-started from where they left off.\n", "\n", "In this demo, we see how we can save a model to a json file and reload it.\n", "\n", "It assumes you have already completed the [data deduplication quick start](quickstart_demo_deduplication.ipynb)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 1: Imports and setup\n", "\n", "The following is just boilerplate code that sets up the Spark session and sets some other non-essential configuration options" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import logging \n", "from utility_functions.demo_utils import get_spark\n", "\n", "logging.basicConfig() # Means logs will print in Jupyter Lab\n", "\n", "# Set to DEBUG if you want splink to log the SQL statements it's executing under the hood\n", "logging.getLogger(\"splink\").setLevel(logging.INFO)\n", "spark = get_spark()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Step 2: Read in data and run linking" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:splink.iterate:Iteration 0 complete\n", "INFO:splink.params:The maximum change in parameters was 0.5087412834167481 for key π_gamma_surname_prob_dist_non_match_level_2_probability\n", "INFO:splink.iterate:Iteration 1 complete\n", "INFO:splink.params:The maximum change in parameters was 0.0954439640045166 for key π_gamma_surname_prob_dist_match_level_2_probability\n", "INFO:splink.iterate:Iteration 2 complete\n", "INFO:splink.params:The maximum change in parameters was 0.021286725997924805 for key π_gamma_dob_prob_dist_non_match_level_0_probability\n", "INFO:splink.iterate:Iteration 3 complete\n", "INFO:splink.params:The maximum change in parameters was 0.010865330696105957 for key π_gamma_dob_prob_dist_non_match_level_0_probability\n", "INFO:splink.iterate:Iteration 4 complete\n", "INFO:splink.params:The maximum change in parameters was 0.008596867322921753 for key π_gamma_email_prob_dist_match_level_0_probability\n" ] }, { "data": { "text/html": [ "
\n", " | tf_adjusted_match_prob | \n", "match_probability | \n", "unique_id_l | \n", "unique_id_r | \n", "first_name_l | \n", "first_name_r | \n", "gamma_first_name | \n", "prob_gamma_first_name_non_match | \n", "prob_gamma_first_name_match | \n", "first_name_adj | \n", "... | \n", "city_l | \n", "city_r | \n", "gamma_city | \n", "prob_gamma_city_non_match | \n", "prob_gamma_city_match | \n", "email_l | \n", "email_r | \n", "gamma_email | \n", "prob_gamma_email_non_match | \n", "prob_gamma_email_match | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0.999991 | \n", "0.999646 | \n", "0 | \n", "3 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.47229 | \n", "0.567037 | \n", "0.975943 | \n", "... | \n", "London | \n", "None | \n", "-1 | \n", "1.00000 | \n", "1.000000 | \n", "hannah88@powers.com | \n", "hannah88opowersc@m | \n", "1 | \n", "0.007089 | \n", "0.894782 | \n", "
1 | \n", "0.999645 | \n", "0.985811 | \n", "0 | \n", "2 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.47229 | \n", "0.567037 | \n", "0.975943 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.14658 | \n", "0.780896 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.007089 | \n", "0.894782 | \n", "
2 | \n", "0.999645 | \n", "0.985811 | \n", "0 | \n", "1 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.47229 | \n", "0.567037 | \n", "0.975943 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.14658 | \n", "0.780896 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.007089 | \n", "0.894782 | \n", "
3 | \n", "0.988914 | \n", "0.916171 | \n", "1 | \n", "3 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.47229 | \n", "0.567037 | \n", "0.975943 | \n", "... | \n", "London | \n", "None | \n", "-1 | \n", "1.00000 | \n", "1.000000 | \n", "hannah88@powers.com | \n", "hannah88opowersc@m | \n", "1 | \n", "0.007089 | \n", "0.894782 | \n", "
4 | \n", "0.997900 | \n", "0.983115 | \n", "1 | \n", "2 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.47229 | \n", "0.567037 | \n", "0.975943 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.14658 | \n", "0.780896 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.007089 | \n", "0.894782 | \n", "
5 rows × 31 columns
\n", "\n", " | tf_adjusted_match_prob | \n", "match_probability | \n", "unique_id_l | \n", "unique_id_r | \n", "first_name_l | \n", "first_name_r | \n", "gamma_first_name | \n", "prob_gamma_first_name_non_match | \n", "prob_gamma_first_name_match | \n", "first_name_adj | \n", "... | \n", "city_l | \n", "city_r | \n", "gamma_city | \n", "prob_gamma_city_non_match | \n", "prob_gamma_city_match | \n", "email_l | \n", "email_r | \n", "gamma_email | \n", "prob_gamma_email_non_match | \n", "prob_gamma_email_match | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1.000000 | \n", "0.999962 | \n", "0 | \n", "3 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.469065 | \n", "0.568189 | \n", "0.995446 | \n", "... | \n", "London | \n", "None | \n", "-1 | \n", "1.000000 | \n", "1.000000 | \n", "hannah88@powers.com | \n", "hannah88opowersc@m | \n", "1 | \n", "0.001349 | \n", "0.875251 | \n", "
1 | \n", "0.999989 | \n", "0.997613 | \n", "0 | \n", "2 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.469065 | \n", "0.568189 | \n", "0.995446 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.140833 | \n", "0.769179 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.001349 | \n", "0.875251 | \n", "
2 | \n", "0.999989 | \n", "0.997613 | \n", "0 | \n", "1 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.469065 | \n", "0.568189 | \n", "0.995446 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.140833 | \n", "0.769179 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.001349 | \n", "0.875251 | \n", "
3 | \n", "0.999653 | \n", "0.984606 | \n", "1 | \n", "3 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.469065 | \n", "0.568189 | \n", "0.995446 | \n", "... | \n", "London | \n", "None | \n", "-1 | \n", "1.000000 | \n", "1.000000 | \n", "hannah88@powers.com | \n", "hannah88opowersc@m | \n", "1 | \n", "0.001349 | \n", "0.875251 | \n", "
4 | \n", "0.999936 | \n", "0.997146 | \n", "1 | \n", "2 | \n", "Julia | \n", "Julia | \n", "2 | \n", "0.469065 | \n", "0.568189 | \n", "0.995446 | \n", "... | \n", "London | \n", "London | \n", "1 | \n", "0.140833 | \n", "0.769179 | \n", "hannah88@powers.com | \n", "hannah88@powers.com | \n", "1 | \n", "0.001349 | \n", "0.875251 | \n", "
5 rows × 31 columns
\n", "