|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import matplotlib.pyplot as plt\n", |
| 10 | + "import seaborn as sns\n", |
| 11 | + "import numpy as np\n", |
| 12 | + "\n", |
| 13 | + "# Define the range for the heatmap\n", |
| 14 | + "min_score = min(stories[\"log_score\"].min(), stories[\"predictions\"].min())\n", |
| 15 | + "max_score = max(stories[\"log_score\"].max(), stories[\"predictions\"].max())\n", |
| 16 | + "\n", |
| 17 | + "# Create a more continuous 2D histogram\n", |
| 18 | + "plt.figure(figsize=(12, 10))\n", |
| 19 | + "sns.kdeplot(\n", |
| 20 | + " data=stories.sample(10000, seed=42),\n", |
| 21 | + " x=\"log_score\",\n", |
| 22 | + " y=\"predictions\",\n", |
| 23 | + " cmap=\"YlOrRd\",\n", |
| 24 | + " fill=True,\n", |
| 25 | + " cbar=True,\n", |
| 26 | + " cbar_kws={\"label\": \"Density\"},\n", |
| 27 | + ")\n", |
| 28 | + "\n", |
| 29 | + "plt.title(\"Density Heatmap of Predicted Score vs Actual Score\")\n", |
| 30 | + "plt.xlabel(\"Actual Score (log_score)\")\n", |
| 31 | + "plt.ylabel(\"Predicted Score\")\n", |
| 32 | + "\n", |
| 33 | + "# Set axis limits to match the data range\n", |
| 34 | + "plt.xlim(min_score, max_score)\n", |
| 35 | + "plt.ylim(min_score, max_score)\n", |
| 36 | + "\n", |
| 37 | + "# Add a diagonal line for reference\n", |
| 38 | + "plt.plot([min_score, max_score], [min_score, max_score], \"k--\", alpha=0.5)\n", |
| 39 | + "\n", |
| 40 | + "plt.tight_layout()\n", |
| 41 | + "plt.show()" |
| 42 | + ] |
| 43 | + } |
| 44 | + ], |
| 45 | + "metadata": { |
| 46 | + "language_info": { |
| 47 | + "name": "python" |
| 48 | + } |
| 49 | + }, |
| 50 | + "nbformat": 4, |
| 51 | + "nbformat_minor": 2 |
| 52 | +} |
0 commit comments