From d9c34e5e55e3713af5eb968876ffa00067e84060 Mon Sep 17 00:00:00 2001 From: Bernhard Merkle Date: Sun, 5 Jan 2025 16:47:57 +0100 Subject: [PATCH] Refactor Explainable AI notebook: update plot configurations like .plot.barh --- ch07/Explainable_AI.ipynb | 52 +++++++++------------------------------ 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/ch07/Explainable_AI.ipynb b/ch07/Explainable_AI.ipynb index 557c245..bb71134 100644 --- a/ch07/Explainable_AI.ipynb +++ b/ch07/Explainable_AI.ipynb @@ -233,14 +233,14 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "Y_pred" + ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "result[result[\"actual\"] != result[\"predicted\"]].head()" @@ -302,9 +302,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -315,9 +313,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": true - }, + "metadata": {}, "outputs": [], "source": [ "wrong[\"max_probability\"].plot.hist(title=\"Wrong\")\n", @@ -433,26 +429,7 @@ "metadata": {}, "outputs": [], "source": [ - "core_ui.set_index(\"feature\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "10*['r']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "core_ui.set_index(\"feature\").plot.barh(color=[['red']*10 + ['green']*10])\n", - "plt.savefig(\"coefficients-core-ui.svg\")" + "core_ui.set_index(\"feature\").plot.barh()" ] }, { @@ -477,8 +454,7 @@ "top_negative_coef = vocabulary_positions[:top_words].tolist()\n", "core = pd.DataFrame([[vocabulary[c], coef[c]] for c in top_positive_coef + top_negative_coef], \n", " columns=[\"feature\", \"coefficient\"]).sort_values(\"coefficient\")\n", - "core.set_index(\"feature\").plot.barh(figsize=(6, 10), color=[['red']*top_words + ['green']*top_words])\n", - "plt.savefig(\"coefficients-core.svg\")" + "core.set_index(\"feature\").plot.barh(figsize=(6, 10))" ] }, { @@ -766,9 +742,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": true - }, + "metadata": {}, "outputs": [], "source": [ "np.random.seed(42)\n", @@ -855,9 +829,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "exp_num.show_in_notebook()" @@ -874,7 +846,7 @@ "metadata": { "celltoolbar": "Slideshow", "kernelspec": { - "display_name": "Python 3", + "display_name": "blueprints", "language": "python", "name": "python3" }, @@ -888,7 +860,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.12.8" }, "toc": { "base_numbering": 1,