.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/svm/plot_svm_tie_breaking.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 JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_svm_plot_svm_tie_breaking.py: ========================================================= مثال على كسر التعادل في SVM ========================================================= كسر التعادل مكلف إذا كان ``decision_function_shape='ovr'``، ولذلك فهو غير مفعل بشكل افتراضي. يوضح هذا المثال تأثير معلمة ``break_ties`` لمشكلة تصنيف متعددة الفئات و ``decision_function_shape='ovr'``. يختلف المخططان فقط في المنطقة الوسطى حيث تكون الفئات متعادلة. إذا كان ``break_ties=False``، فسيتم تصنيف جميع المدخلات في تلك المنطقة على أنها فئة واحدة، في حين أنه إذا كان ``break_ties=True``، فإن آلية كسر التعادل ستخلق حدود قرار غير محدبة في تلك المنطقة. .. GENERATED FROM PYTHON SOURCE LINES 10-60 .. image-sg:: /auto_examples/svm/images/sphx_glr_plot_svm_tie_breaking_001.png :alt: break_ties = False, break_ties = True :srcset: /auto_examples/svm/images/sphx_glr_plot_svm_tie_breaking_001.png :class: sphx-glr-single-img .. code-block:: Python # المؤلفون: مطوري scikit-learn # معرف الترخيص: BSD-3-Clause import matplotlib.pyplot as plt import numpy as np from sklearn.datasets import make_blobs from sklearn.svm import SVC X, y = make_blobs(random_state=27) fig, sub = plt.subplots(2, 1, figsize=(5, 8)) titles = ("break_ties = False", "break_ties = True") for break_ties, title, ax in zip((False, True), titles, sub.flatten()): svm = SVC( kernel="linear", C=1, break_ties=break_ties, decision_function_shape="ovr" ).fit(X, y) xlim = [X[:, 0].min(), X[:, 0].max()] ylim = [X[:, 1].min(), X[:, 1].max()] xs = np.linspace(xlim[0], xlim[1], 1000) ys = np.linspace(ylim[0], ylim[1], 1000) xx, yy = np.meshgrid(xs, ys) pred = svm.predict(np.c_[xx.ravel(), yy.ravel()]) colors = [plt.cm.Accent(i) for i in [0, 4, 7]] points = ax.scatter(X[:, 0], X[:, 1], c=y, cmap="Accent") classes = [(0, 1), (0, 2), (1, 2)] line = np.linspace(X[:, 1].min() - 5, X[:, 1].max() + 5) ax.imshow( -pred.reshape(xx.shape), cmap="Accent", alpha=0.2, extent=(xlim[0], xlim[1], ylim[1], ylim[0]), ) for coef, intercept, col in zip(svm.coef_, svm.intercept_, classes): line2 = -(line * coef[1] + intercept) / coef[0] ax.plot(line2, line, "-", c=colors[col[0]]) ax.plot(line2, line, "--", c=colors[col[1]]) ax.set_xlim(xlim) ax.set_ylim(ylim) ax.set_title(title) ax.set_aspect("equal") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.021 seconds) .. _sphx_glr_download_auto_examples_svm_plot_svm_tie_breaking.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/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/svm/plot_svm_tie_breaking.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/svm/plot_svm_tie_breaking.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_svm_tie_breaking.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_svm_tie_breaking.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_svm_tie_breaking.zip ` .. include:: plot_svm_tie_breaking.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_