{"spec_id":"learning-curve-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nlearning-curve-basic: Model Learning Curve\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-10\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Okabe-Ito palette (first series always #009E73)\nTRAIN_COLOR = \"#009E73\"\nVAL_COLOR = \"#C475FD\"\n\n# Data - Simulating a learning curve with typical patterns\nnp.random.seed(42)\n\n# Training set sizes\ntrain_sizes = np.array([50, 100, 200, 400, 600, 800, 1000, 1200, 1500, 2000])\nn_sizes = len(train_sizes)\nn_folds = 5\n\n# Generate realistic learning curve pattern:\n# - Training score starts high and slightly decreases (model fits less perfectly with more data)\n# - Validation score starts low and increases (model generalizes better with more data)\n# - Gap narrows as training size increases\n\n# Training scores - high and slightly decreasing\ntrain_base = 0.98 - 0.03 * (train_sizes / train_sizes.max())\ntrain_scores = np.array([train_base + np.random.normal(0, 0.01, n_sizes) for _ in range(n_folds)])\ntrain_scores = np.clip(train_scores, 0.85, 1.0)\n\n# Validation scores - starts lower, increases with more data\nval_base = 0.65 + 0.25 * (1 - np.exp(-train_sizes / 500))\nvalidation_scores = np.array([val_base + np.random.normal(0, 0.02, n_sizes) for _ in range(n_folds)])\nvalidation_scores = np.clip(validation_scores, 0.55, 0.95)\n\n# Calculate means and standard deviations\ntrain_mean = train_scores.mean(axis=0)\ntrain_std = train_scores.std(axis=0)\nval_mean = validation_scores.mean(axis=0)\nval_std = validation_scores.std(axis=0)\n\n# Configure seaborn theme with adaptive colors\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\nsns.set_context(\"talk\", font_scale=1.1)\n\n# Plot setup\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\n\n# Plot training curve with confidence band\nax.fill_between(train_sizes, train_mean - train_std, train_mean + train_std, alpha=0.2, color=TRAIN_COLOR)\nsns.lineplot(\n    x=train_sizes,\n    y=train_mean,\n    ax=ax,\n    color=TRAIN_COLOR,\n    linewidth=3,\n    marker=\"o\",\n    markersize=10,\n    label=\"Training Score\",\n)\n\n# Plot validation curve with confidence band\nax.fill_between(train_sizes, val_mean - val_std, val_mean + val_std, alpha=0.2, color=VAL_COLOR)\nsns.lineplot(\n    x=train_sizes, y=val_mean, ax=ax, color=VAL_COLOR, linewidth=3, marker=\"s\", markersize=10, label=\"Validation Score\"\n)\n\n# Labels and styling\nax.set_xlabel(\"Training Set Size (samples)\", fontsize=20, color=INK)\nax.set_ylabel(\"Accuracy Score (0-1)\", fontsize=20, color=INK)\nax.set_title(\"learning-curve-basic · seaborn · anyplot.ai\", fontsize=24, color=INK, fontweight=\"medium\")\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Set y-axis limits for better visualization\nax.set_ylim(0.5, 1.02)\n\n# Configure legend\nax.legend(fontsize=16, loc=\"lower right\", framealpha=0.95)\n\n# Subtle grid (y-axis only)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8)\n\n# Remove top and right spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"left\"].set_color(INK_SOFT)\nax.spines[\"bottom\"].set_color(INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}