.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/linear_model/plot_logistic_path.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_linear_model_plot_logistic_path.py: ============================================== مسار التنظيم لـ L1 - الانحدار اللوجستي ============================================== قم بتدريب نماذج الانحدار اللوجستي المنتظمة بـ L1 على مشكلة تصنيف ثنائي مستمدة من مجموعة بيانات Iris. تم ترتيب النماذج من الأكثر تنظيماً إلى الأقل تنظيماً. تم جمع المعاملات الأربعة للنماذج وتم رسمها كـ "مسار تنظيم": على الجانب الأيسر من الشكل (المنظمون الأقوياء)، جميع المعاملات تساوي بالضبط 0. عندما يصبح التنظيم تدريجياً أكثر مرونة، يمكن للمعاملات الحصول على قيم غير صفرية واحدة تلو الأخرى. هنا نختار محدد liblinear لأنه يمكنه تحسين خسارة الانحدار اللوجستي بكفاءة مع عقوبة L1 غير الملساء، والتي تحفز على التباعد. لاحظ أيضاً أننا نحدد قيمة منخفضة للتسامح للتأكد من أن النموذج قد تقارب قبل جمع المعاملات. نستخدم أيضاً warm_start=True مما يعني أن معاملات النماذج يتم إعادة استخدامها لتهيئة النموذج التالي لتسريع حساب المسار الكامل. .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: Python # المؤلفون: مطوري سكايلرن # معرف الترخيص: BSD-3-Clause .. GENERATED FROM PYTHON SOURCE LINES 30-32 تحميل البيانات --------- .. GENERATED FROM PYTHON SOURCE LINES 32-44 .. code-block:: Python from sklearn import datasets iris = datasets.load_iris() X = iris.data y = iris.target X = X[y != 2] y = y[y != 2] X /= X.max() # تطبيع X لتسريع التقارب .. GENERATED FROM PYTHON SOURCE LINES 45-47 حساب مسار التنظيم --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-71 .. code-block:: Python import numpy as np from sklearn import linear_model from sklearn.svm import l1_min_c cs = l1_min_c(X, y, loss="log") * np.logspace(0, 10, 16) clf = linear_model.LogisticRegression( penalty="l1", solver="liblinear", tol=1e-6, max_iter=int(1e6), warm_start=True, intercept_scaling=10000.0, ) coefs_ = [] for c in cs: clf.set_params(C=c) clf.fit(X, y) coefs_.append(clf.coef_.ravel().copy()) coefs_ = np.array(coefs_) .. GENERATED FROM PYTHON SOURCE LINES 72-74 رسم مسار التنظيم ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 74-83 .. code-block:: Python import matplotlib.pyplot as plt plt.plot(np.log10(cs), coefs_, marker="o") ymin, ymax = plt.ylim() plt.xlabel("log(C)") plt.ylabel("Coefficients") plt.title("Logistic Regression Path") plt.axis("tight") plt.show() .. image-sg:: /auto_examples/linear_model/images/sphx_glr_plot_logistic_path_001.png :alt: Logistic Regression Path :srcset: /auto_examples/linear_model/images/sphx_glr_plot_logistic_path_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.110 seconds) .. _sphx_glr_download_auto_examples_linear_model_plot_logistic_path.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/linear_model/plot_logistic_path.ipynb :alt: Launch binder :width: 150 px .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/index.html?path=auto_examples/linear_model/plot_logistic_path.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_logistic_path.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_logistic_path.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_logistic_path.zip ` .. include:: plot_logistic_path.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_