{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pronunciation-based location prediction confusion\n", "\n", "Confusion of pronunciation-based predictions of someone's location" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "import folium\n", "import pandas\n", "import MySQLdb\n", "import numpy\n", "from sklearn.metrics import confusion_matrix\n", "from folium.plugins import HeatMap\n", "from IPython.display import display\n", "import itertools\n", "import requests\n", "import json\n", "import random\n", "from vincenty import vincenty\n", "\n", "db = MySQLdb.connect(user='root', passwd='Nmmxhjgt1@', db='stimmenfryslan')\n", "\n", "\n", "%matplotlib inline\n", "from matplotlib import pyplot, rcParams\n", "from jupyter_progressbar import ProgressBar\n", "\n", "# rcParams['font.family'] = 'Lucinda Console'\n", "rcParams['font.size'] = '24'\n", "rcParams['figure.figsize'] = (20, 10)\n", "rcParams['figure.dpi'] = 100\n", "\n", "from jupyter_progressbar import ProgressBar" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "with open('simplified_predictions.p3', 'rb') as f:\n", " simplified_predictions = pickle.load(f)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "simplified_predictions['actual_latlon_rounded'] = [\n", " (\n", " (x[0] // 0.1) * 0.1,\n", " (x[1] // 0.1) * 0.1,\n", " ) if x == x else numpy.nan\n", " for x in simplified_predictions['actual_latlon']\n", "]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "actual_latlon = [tuple(x) for x in simplified_predictions['actual_latlon'] if x == x]\n", "\n", "m = folium.Map((52.16370310266682, 5.601701825033824), tiles='stamentoner', zoom_start=8)\n", "\n", "for p in set(actual_latlon):\n", " if p == p:\n", " pp = ((p[0] // 0.1) * 0.1, (p[1] // 0.1) * 0.1)\n", " folium.Circle(pp, radius=10).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "from collections import Counter" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9b3470db2073443a9ee9ed47076116b9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(FloatProgress(value=0.0, max=1.0), HTML(value='0s passed', placeholder='0…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "confusions = Counter([\n", " (tuple(actual), tuple(predicted))\n", " for actual, predicted in zip(\n", " ProgressBar(simplified_predictions['actual_latlon_rounded']),\n", " simplified_predictions['prediction_1_latlon']\n", " )\n", " if actual == actual and predicted == predicted\n", "])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = folium.Map((52.16370310266682, 5.601701825033824), tiles='stamentoner', zoom_start=8)\n", "\n", "for (actual, predicted), count in confusions.items():\n", " \n", " folium.PolyLine([actual, predicted], color=\"red\", weight=numpy.log(count), opacity=1).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map((52.16370310266682, 5.601701825033824), tiles='stamentoner', zoom_start=8)\n", "\n", "for (actual, predicted), count in confusions.items():\n", " \n", " folium.PolyLine([actual, predicted], color=\"red\", weight=numpy.log(count), opacity=1).add_to(m)\n", "\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }