{ "cells": [ { "cell_type": "markdown", "id": "96d8501c", "metadata": {}, "source": [ "# Home Location Inference" ] }, { "cell_type": "code", "execution_count": 1, "id": "ec77078c", "metadata": {}, "outputs": [], "source": [ "from cider.datastore import DataStore\n", "from cider.home_location import HomeLocator" ] }, { "cell_type": "markdown", "id": "7f3fd778", "metadata": {}, "source": [ "Load some CDR data, antennas data, and (optionally) spatial files, whose paths have been defined in `config.yml`. Define the geographic granularity for inference (options are ‘antenna_id’, ‘tower_id’ if a tower_id is provided in the antennas files, or any of the spatial files). Optionally load wealth prediction data to construct a poverty map and ground truth location data to evaluate accuracy." ] }, { "cell_type": "code", "execution_count": 3, "id": "44d61e7d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading CDR...\n", "Loading antennas...\n", "Warning: 10 antennas missing location\n" ] } ], "source": [ "# This path should point to your cider installation, where configs and data for this demo are located.\n", "from pathlib import Path\n", "cider_installation_directory = Path('../../cider')\n", "\n", "datastore = DataStore(config_file_path_string= cider_installation_directory / 'configs' / 'config_quickstart.yml')\n", "home_locator = HomeLocator(datastore=datastore, clean_folders=True)" ] }, { "cell_type": "markdown", "id": "be520940", "metadata": {}, "source": [ "Filter to a specific date range." ] }, { "cell_type": "code", "execution_count": 4, "id": "7060dbd4", "metadata": {}, "outputs": [], "source": [ "home_locator.ds.filter_dates('2020-01-05', '2020-02-01')" ] }, { "cell_type": "markdown", "id": "feeb0a77", "metadata": {}, "source": [ "Try running the three different home location algorithms, specifying towers as the requested geographic level of aggregation." ] }, { "cell_type": "markdown", "id": "633a882d", "metadata": {}, "source": [ "```{note}\n", "The three algorithms currently implemented are relatively simple; more sophisticate methods to infer users' home locations do exist.\n", "```" ] }, { "cell_type": "code", "execution_count": 5, "id": "0702d156", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " \r" ] }, { "data": { "text/html": [ "
\n", " | subscriber_id | \n", "tower_id | \n", "count_modal_days | \n", "
---|---|---|---|
0 | \n", "JGPCbfDGes | \n", "t35 | \n", "4 | \n", "
1 | \n", "YtvkGlMWwe | \n", "t39 | \n", "4 | \n", "
2 | \n", "dYwshzRseD | \n", "t26 | \n", "4 | \n", "
3 | \n", "dsBHAdXrrk | \n", "t35 | \n", "2 | \n", "
4 | \n", "ygMEXUQDbn | \n", "t27 | \n", "4 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
995 | \n", "amzyXHglBx | \n", "t7 | \n", "3 | \n", "
996 | \n", "dJSvXqUVSY | \n", "t64 | \n", "3 | \n", "
997 | \n", "ptudOnjdRU | \n", "t35 | \n", "5 | \n", "
998 | \n", "uXZrufHOmE | \n", "t79 | \n", "4 | \n", "
999 | \n", "zZkqaZFAtz | \n", "t80 | \n", "4 | \n", "
1000 rows × 3 columns
\n", "\n", " | tower_id | \n", "recall | \n", "precision | \n", "overall_accuracy | \n", "
---|---|---|---|---|
67 | \n", "t7 | \n", "0.076923 | \n", "0.166667 | \n", "0.017 | \n", "
15 | \n", "t22 | \n", "0.250000 | \n", "0.142857 | \n", "0.017 | \n", "
33 | \n", "t39 | \n", "0.214286 | \n", "0.090909 | \n", "0.017 | \n", "
66 | \n", "t69 | \n", "0.100000 | \n", "0.055556 | \n", "0.017 | \n", "
37 | \n", "t42 | \n", "0.153846 | \n", "0.055556 | \n", "0.017 | \n", "