.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/neighbors/plot_regression.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_neighbors_plot_regression.py: ======================= أقرب جيران الانحدار ======================= توضيح حل مشكلة الانحدار باستخدام أقرب جيران k- ونظام الاستيفاء للهدف باستخدام كل من الأوزان الثابتة والمركز الثقل. .. GENERATED FROM PYTHON SOURCE LINES 10-15 توليد بيانات العينة -------------------- هنا نقوم بتوليد بعض نقاط البيانات لاستخدامها في تدريب النموذج. كما نقوم بتوليد بيانات في النطاق الكامل لبيانات التدريب لتوضيح كيفية تفاعل النموذج في تلك المنطقة بالكامل. .. GENERATED FROM PYTHON SOURCE LINES 15-29 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from sklearn import neighbors rng = np.random.RandomState(0) X_train = np.sort(5 * rng.rand(40, 1), axis=0) X_test = np.linspace(0, 5, 500)[:, np.newaxis] y = np.sin(X_train).ravel() # إضافة ضوضاء إلى الأهداف y[::5] += 1 * (0.5 - np.random.rand(8)) .. GENERATED FROM PYTHON SOURCE LINES 30-34 نموذج الانحدار المناسب -------------------- هنا نقوم بتدريب نموذج وتوضيح كيفية تأثير الأوزان 'الموحدة' و 'المسافة' في التنبؤ بالقيم المتوقعة. .. GENERATED FROM PYTHON SOURCE LINES 34-49 .. code-block:: Python n_neighbors = 5 for i, weights in enumerate(["uniform", "distance"]): knn = neighbors.KNeighborsRegressor(n_neighbors, weights=weights) y_ = knn.fit(X_train, y).predict(X_test) plt.subplot(2, 1, i + 1) plt.scatter(X_train, y, color="darkorange", label="data") plt.plot(X_test, y_, color="navy", label="prediction") plt.axis("tight") plt.legend() plt.title("KNeighborsRegressor (k = %i, weights = '%s')" % (n_neighbors, weights)) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/neighbors/images/sphx_glr_plot_regression_001.png :alt: KNeighborsRegressor (k = 5, weights = 'uniform'), KNeighborsRegressor (k = 5, weights = 'distance') :srcset: /auto_examples/neighbors/images/sphx_glr_plot_regression_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.282 seconds) .. _sphx_glr_download_auto_examples_neighbors_plot_regression.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/neighbors/plot_regression.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/neighbors/plot_regression.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_regression.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_regression.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_regression.zip ` .. include:: plot_regression.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_