Skip to content

Commit

Permalink
Merge branch 'master' into Uganda_2019_intercomparison
Browse files Browse the repository at this point in the history
  • Loading branch information
adebowaledaniel authored Nov 27, 2023
2 parents 9c7184b + badbf72 commit 9f99eff
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions notebooks/crop_area_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
" compute_confusion_matrix,\n",
" compute_area_estimate,\n",
" create_area_estimate_summary,\n",
" compute_area_error_matrix,\n",
" create_confusion_matrix_summary\n",
")\n"
]
Expand Down Expand Up @@ -552,7 +553,7 @@
"metadata": {},
"outputs": [],
"source": [
"def plot_confusion_matrix(cm,labels) -> None:\n",
"def plot_confusion_matrix(cm, labels, datatype=\"d\") -> None:\n",
" \"\"\"Pretty prints confusion matrix.\n",
"\n",
" Expects row 'Reference' and column 'Prediction/Map' ordered confusion matrix.\n",
Expand All @@ -572,14 +573,15 @@
" \"\"\"\n",
"\n",
" _, ax = plt.subplots(nrows=1, ncols=1)\n",
" sns.heatmap(cm, cmap=\"crest\", annot=True, fmt=\"d\", cbar=False, square=True, ax=ax)\n",
" sns.heatmap(cm, cmap=\"crest\", annot=True, fmt=datatype, cbar=False, \n",
" square=True, ax=ax, annot_kws={\"size\": 20})\n",
" ax.xaxis.tick_top()\n",
" ax.xaxis.set_label_coords(0.50, 1.125)\n",
" ax.yaxis.set_label_coords(-0.125, 0.50)\n",
" ax.set_xticklabels(labels=labels)\n",
" ax.set_yticklabels(labels=labels)\n",
" ax.set_xlabel(\"Map\", fontsize=12)\n",
" ax.set_ylabel(\"Reference\", fontsize=12)\n",
" ax.set_xticklabels(labels=labels, fontsize=16)\n",
" ax.set_yticklabels(labels=labels, fontsize=16)\n",
" ax.set_xlabel(\"Map\", fontsize=20)\n",
" ax.set_ylabel(\"Reference\", fontsize=20)\n",
" plt.tight_layout()"
]
},
Expand Down Expand Up @@ -626,6 +628,20 @@
"estimates = compute_area_estimate(cm, a_j, px_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot the error matrix expressed in terms of proportion of area\n",
"# as suggested by good practice recommendations\n",
"total_px = a_j.sum()\n",
"w_j = a_j / total_px\n",
"am = compute_area_error_matrix(cm, w_j)\n",
"plot_confusion_matrix(am, labels, datatype=\"0.2f\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit 9f99eff

Please sign in to comment.