{"spec_id":"learning-curve-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nlearning-curve-basic: Model Learning Curve\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-10\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"\nACCENT = \"#C475FD\"\n\n# Data - Simulate learning curve for a model\nnp.random.seed(42)\n\n# Training set sizes (10 different sizes)\ntrain_sizes = np.array([50, 100, 200, 400, 600, 800, 1000, 1200, 1400, 1600])\n\n# Simulate 5 cross-validation folds\nn_folds = 5\nn_sizes = len(train_sizes)\n\n# Training scores: Start high, stay high (model fits training data well)\ntrain_scores_mean = 0.99 - 0.15 * np.exp(-train_sizes / 200)\ntrain_scores = np.zeros((n_folds, n_sizes))\nfor i in range(n_folds):\n    noise = np.random.randn(n_sizes) * 0.01\n    train_scores[i] = train_scores_mean + noise\n\n# Validation scores: Start lower, improve with more data (learning effect)\nvalidation_scores_mean = 0.65 + 0.20 * (1 - np.exp(-train_sizes / 500))\nvalidation_scores = np.zeros((n_folds, n_sizes))\nfor i in range(n_folds):\n    noise = np.random.randn(n_sizes) * 0.02\n    validation_scores[i] = validation_scores_mean + noise\n\n# Calculate means and standard deviations\ntrain_mean = np.mean(train_scores, axis=0)\ntrain_std = np.std(train_scores, axis=0)\nval_mean = np.mean(validation_scores, axis=0)\nval_std = np.std(validation_scores, axis=0)\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Training curve with confidence band\nax.fill_between(train_sizes, train_mean - train_std, train_mean + train_std, alpha=0.15, color=BRAND)\nax.plot(train_sizes, train_mean, \"o-\", color=BRAND, linewidth=3, markersize=10, label=\"Training Score\")\n\n# Validation curve with confidence band\nax.fill_between(train_sizes, val_mean - val_std, val_mean + val_std, alpha=0.15, color=ACCENT)\nax.plot(train_sizes, val_mean, \"s-\", color=ACCENT, linewidth=3, markersize=10, label=\"Validation Score\")\n\n# Labels and styling\nax.set_xlabel(\"Training Set Size (samples)\", fontsize=20, color=INK)\nax.set_ylabel(\"Accuracy Score\", fontsize=20, color=INK)\nax.set_title(\"learning-curve-basic · matplotlib · anyplot.ai\", fontsize=24, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Grid\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\n\n# Legend\nleg = ax.legend(fontsize=16, loc=\"lower right\")\nif leg:\n    leg.get_frame().set_facecolor(PAGE_BG)\n    leg.get_frame().set_edgecolor(INK_SOFT)\n    plt.setp(leg.get_texts(), color=INK_SOFT)\n\n# Set y-axis limits to show full range with some padding\nax.set_ylim(0.55, 1.02)\nax.set_xlim(0, 1700)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}