.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/linear_model/plot_iris_logistic.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_linear_model_plot_iris_logistic.py: ========================================================= 逻辑回归三分类器 ========================================================= 下图展示了逻辑回归分类器在 `iris `_ 数据集的前两个维度(花萼长度和宽度)上的决策边界。数据点根据其标签进行着色。 .. GENERATED FROM PYTHON SOURCE LINES 9-51 .. image-sg:: /auto_examples/linear_model/images/sphx_glr_plot_iris_logistic_001.png :alt: plot iris logistic :srcset: /auto_examples/linear_model/images/sphx_glr_plot_iris_logistic_001.png :class: sphx-glr-single-img .. code-block:: Python # 代码来源:Gaël Varoquaux # 由Jaques Grobler修改用于文档 # SPDX许可证标识符:BSD-3-Clause import matplotlib.pyplot as plt from sklearn import datasets from sklearn.inspection import DecisionBoundaryDisplay from sklearn.linear_model import LogisticRegression # 导入一些数据来玩玩 iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. Y = iris.target # 创建一个逻辑回归分类器实例并拟合数据。 logreg = LogisticRegression(C=1e5) logreg.fit(X, Y) _, ax = plt.subplots(figsize=(4, 3)) DecisionBoundaryDisplay.from_estimator( logreg, X, cmap=plt.cm.Paired, ax=ax, response_method="predict", plot_method="pcolormesh", shading="auto", xlabel="Sepal length", ylabel="Sepal width", eps=0.5, ) # 还要绘制训练点 plt.scatter(X[:, 0], X[:, 1], c=Y, edgecolors="k", cmap=plt.cm.Paired) plt.xticks(()) plt.yticks(()) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.023 seconds) .. _sphx_glr_download_auto_examples_linear_model_plot_iris_logistic.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_iris_logistic.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_iris_logistic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_iris_logistic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_iris_logistic.zip ` .. include:: plot_iris_logistic.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_