.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_runtime_vs_performance.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_runtime_vs_performance.py: ================================================== MILP Solve Time vs. Feature & Sample Dimensions ================================================== This example evaluates how execution time scales with feature count :math:`p` and sample size :math:`n` when optimizing exact ternary weights via MILP. .. GENERATED FROM PYTHON SOURCE LINES 9-43 .. image-sg:: /auto_examples/images/sphx_glr_plot_runtime_vs_performance_001.png :alt: TlmMilpClassifier Execution Time Scaling :srcset: /auto_examples/images/sphx_glr_plot_runtime_vs_performance_001.png :class: sphx-glr-single-img .. code-block:: Python import time import matplotlib.pyplot as plt from sklearn.datasets import make_classification from tlmnet import TlmMilpClassifier feature_counts = [5, 10, 15, 20, 25] sample_sizes = [50, 100, 200] results: dict[int, list[float]] = {n: [] for n in sample_sizes} for n in sample_sizes: for p in feature_counts: X, y = make_classification( n_samples=n, n_features=p, n_informative=min(p, 3), random_state=42 ) clf = TlmMilpClassifier(max_features=5, C=1.0) start = time.time() clf.fit(X, y) elapsed = time.time() - start results[n].append(elapsed) plt.figure(figsize=(8, 5)) for n in sample_sizes: plt.plot(feature_counts, results[n], marker="o", label=f"n = {n} samples") plt.xlabel("Number of Features (p)") plt.ylabel("MILP Solve Time (seconds)") plt.title("TlmMilpClassifier Execution Time Scaling") plt.legend() plt.grid(True) plt.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.278 seconds) .. _sphx_glr_download_auto_examples_plot_runtime_vs_performance.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_runtime_vs_performance.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_runtime_vs_performance.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_runtime_vs_performance.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_