Skip to content

Commit

Permalink
Add initial twitter results plots
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashu1 committed May 2, 2018
1 parent c07a807 commit 38f09a6
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 3 deletions.
143 changes: 140 additions & 3 deletions investigate-results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"2. Plot **ROC curves** for inputted network, visibility, and link prediction method\n",
"3. **Save ROC AUC/AP plots** as .pdf files\n",
"4. **Save minimum runtime plots** as .pdf files\n",
"5. **Save network statistics** as .txt files"
"5. **Save network statistics** as .txt files\n",
"6. Generate **ROC Plots by Algorithm**\n",
"7. Generate **Twitter Results** Plots"
]
},
{
Expand Down Expand Up @@ -548,7 +550,7 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": 14,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -696,7 +698,9 @@
{
"cell_type": "code",
"execution_count": 271,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Generate AUROC graphs for each algorithm, frac_hidden\n",
Expand All @@ -712,6 +716,139 @@
" sizes='small')"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## 7. Twitter Results Plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Runtime Plots"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"RESULTS_FOLDER = \"./results/\"\n",
"\n",
"# Get minimum runtimes across Twitter experiments\n",
"twitter_min_runtimes = {}\n",
"TWITTER_EXPERIMENT_NUMS = [0, 1, 2]\n",
"\n",
"# Iterate over all Twitter experiments, store minimum runtimes\n",
"for twitter_num in TWITTER_EXPERIMENT_NUMS:\n",
" # Load in results for this experiment\n",
" curr_fb_dict = None\n",
" twitter_filename = './results/twitter-experiment-{}-results.json'.format(twitter_num)\n",
" with open(twitter_filename, 'rb') as f:\n",
" curr_twitter_dict = json.load(f)\n",
" \n",
" # Iterate over experiments in curr_twitter_dict\n",
" for experiment, results in curr_twitter_dict.iteritems():\n",
" # Create (method --> runtime) dict, if necessary\n",
" if experiment not in twitter_min_runtimes:\n",
" twitter_min_runtimes[experiment] = {}\n",
" \n",
" # Iterate over link prediction methods in current network & experiment\n",
" for method, metrics in results.iteritems():\n",
" # Method currently has recorded runtime\n",
" if method in twitter_min_runtimes[experiment]: \n",
" # Overwrite previous runtime\n",
" if metrics['runtime'] < twitter_min_runtimes[experiment][method]:\n",
" twitter_min_runtimes[experiment][method] = metrics['runtime']\n",
" # Method does not yet have recorded runtime\n",
" else:\n",
" twitter_min_runtimes[experiment][method] = metrics['runtime']"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Plot runtime bar plots for all experiments\n",
"import matplotlib.pyplot as plt\n",
"for experiment_name, runtime_dict in twitter_min_runtimes.iteritems():\n",
" descriptors = experiment_name.split('-')\n",
" ego_num = descriptors[1]\n",
" amt_hidden = descriptors[2]\n",
" graph_title = \"Link Prediction Runtimes: Twitter-{} graph, {} hidden\".format(ego_num, amt_hidden)\n",
" \n",
" plt.figure(figsize=(8, 4))\n",
" plt.bar(range(len(runtime_dict)), runtime_dict.values())\n",
" plt.xticks(range(len(runtime_dict)), list(runtime_dict.keys()))\n",
" plt.grid(linestyle='dashed')\n",
" \n",
" plt.xlabel(\"Link prediction methods\")\n",
" plt.ylabel(\"Minimum runtime (seconds)\")\n",
" plt.title(graph_title)\n",
" \n",
" plt.savefig('./result-plots-by-graph/' + experiment_name + '-runtime.pdf')\n",
" plt.clf()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ROC AUC Plots"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# Save bar plot in .pdf given metric name, metric dict (with results for each method), experiment name\n",
"RESULT_PLOTS_FOLDER = './result-plots-by-graph/'\n",
"twitter_results = None\n",
"with open('./results/twitter-experiment-0-results.json', 'rb') as f:\n",
" twitter_results = json.load(f)\n",
" \n",
"# Save Twitter results bar plot\n",
"def save_twitter_bar_plot(metric_name, metric_dict, experiment_name):\n",
" descriptors = experiment_name.split('-')\n",
" ego_num = descriptors[1]\n",
" amt_hidden = descriptors[2]\n",
" graph_title = \"Link Prediction Results: Twitter-{} graph, {} hidden\".format(ego_num, amt_hidden)\n",
" \n",
" plt.figure(figsize=(8, 4))\n",
" plt.bar(range(len(metric_dict)), metric_dict.values())\n",
" plt.xticks(range(len(metric_dict)), list(metric_dict.keys()))\n",
" plt.grid(linestyle='dashed')\n",
" \n",
" plt.xlabel(\"Link prediction methods\")\n",
" plt.ylabel(\"Metric: {}\".format(metric_name))\n",
" plt.title(graph_title)\n",
" \n",
" plt.savefig(RESULT_PLOTS_FOLDER + experiment_name + '-' + metric_name + '.pdf')\n",
" plt.clf()\n",
" \n",
"# Plot ROC AUC bar graphs for each amt_hidden\n",
"for experiment_name, results_dict in twitter_results.iteritems():\n",
" roc_dict = dict()\n",
" \n",
" # Populate metric_dict with results for each method\n",
" for method, method_results_dict in results_dict.iteritems():\n",
" roc_dict[method] = method_results_dict['test_roc']\n",
"\n",
" # Generate plot for this method and experiment name\n",
" save_twitter_bar_plot(\"test_roc\", roc_dict, experiment_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 38f09a6

Please sign in to comment.