.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_mlops/plot_40_benchmark.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_mlops_plot_40_benchmark.py: A small benchmark of methods ============================ :func:`~eqdisco.benchmarks.run_benchmark` runs several estimators on several problems with repeated seeds and records test accuracy, model size, time and the recovery of the ground truth by the criterion of SRBench (La Cava et al., 2021). The budgets here are small so that the example runs in a minute; the same call with larger budgets and more problems reproduces a proper comparison. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import eqdisco as eq from eqdisco.benchmarks import run_benchmark, summarize .. GENERATED FROM PYTHON SOURCE LINES 19-21 Five methods, six problems -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-47 .. code-block:: Python methods = { "GP": eq.SymbolicRegressor(population_size=200, generations=20, functions=("add", "sub", "mul", "div", "sin", "cos", "exp", "log")), "GP + LM": eq.SymbolicRegressor(population_size=200, generations=20, optimize="lm", functions=("add", "sub", "mul", "div", "sin", "cos", "exp", "log")), "MGGP": eq.MultiGeneRegressor(population_size=200, generations=20, functions=("add", "sub", "mul", "div", "sin", "cos")), "FFX": eq.FFXRegressor(), "STLSQ": eq.SparseRegressor(degree=4, functions=("sin", "cos", "exp", "log")), } problems = ["nguyen-1", "nguyen-5", "nguyen-7", "keijzer-11", "keijzer-14", "feynman-I.12.2"] results = run_benchmark(methods, problems, n_runs=2) print(summarize(results).round(3)) fig, axs = plt.subplots(1, 2, figsize=(10, 3.6)) r = results.copy() r["1-r2"] = (1 - r["r2_test"]).clip(lower=1e-12) eq.viz.plot_benchmark(r, metric="1-r2", ax=axs[0]) axs[0].set_yscale("log") axs[0].set_ylabel("$1-R^2$ on test data") s = summarize(results) order = list(dict.fromkeys(results["method"])) # same colours as the box plots colour = {m: eq.viz.OKABE_ITO[k % len(eq.viz.OKABE_ITO)] for k, m in enumerate(order)} axs[1].scatter(s["median_size"], s["solution_rate"], s=60, color=[colour[m] for m in s.index]) for k, (name, row) in enumerate(s.sort_values("median_size").iterrows()): axs[1].annotate(name, (row["median_size"], row["solution_rate"]), xytext=(6, 6 if k % 2 else -12), textcoords="offset points", fontsize=8) axs[1].set_xlabel("median model size") axs[1].set_ylabel("share of exact recoveries") fig.tight_layout() .. image-sg:: /auto_examples/10_mlops/images/sphx_glr_plot_40_benchmark_001.png :alt: plot 40 benchmark :srcset: /auto_examples/10_mlops/images/sphx_glr_plot_40_benchmark_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none median_r2_test median_size solution_rate median_time method MGGP 1.000 30.5 0.250 0.703 GP + LM 1.000 25.5 0.250 1.022 GP 1.000 15.5 0.167 0.419 STLSQ 0.991 65.0 0.167 0.001 FFX 0.976 45.5 0.000 0.032 .. GENERATED FROM PYTHON SOURCE LINES 48-50 Parameter study: noise ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 50-63 .. code-block:: Python fig, ax = plt.subplots(figsize=(4.8, 3.2)) for k, name in enumerate(("GP", "FFX")): med = [] for nz in (0.0, 0.01, 0.1): rr = run_benchmark({name: methods[name]}, ["nguyen-7", "keijzer-11"], n_runs=1, noise=nz) med.append(rr["r2_test"].median()) print(name, "median test R2 by noise (0, 0.01, 0.1):", np.round(med, 4).tolist()) ax.plot([0, 0.01, 0.1], med, "o-", color=eq.viz.OKABE_ITO[k], label=name) ax.set_xscale("symlog", linthresh=0.01) ax.set_xlabel("noise level (training data)") ax.set_ylabel("median test $R^2$") ax.legend(frameon=False, fontsize=8) plt.show() .. image-sg:: /auto_examples/10_mlops/images/sphx_glr_plot_40_benchmark_002.png :alt: plot 40 benchmark :srcset: /auto_examples/10_mlops/images/sphx_glr_plot_40_benchmark_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none GP median test R2 by noise (0, 0.01, 0.1): [0.9756, 0.9752, 0.9737] FFX median test R2 by noise (0, 0.01, 0.1): [0.9788, 0.9792, 0.9765] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 41.082 seconds) .. _sphx_glr_download_auto_examples_10_mlops_plot_40_benchmark.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/eqdisco/main?urlpath=lab/tree/notebooks/auto_examples/10_mlops/plot_40_benchmark.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_40_benchmark.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_40_benchmark.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_40_benchmark.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_