.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/model_selection/plot_validation_curve.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_model_selection_plot_validation_curve.py: ========================== 绘制验证曲线 ========================== 在此图中,您可以看到支持向量机(SVM)在不同核参数 gamma 值下的训练分数和验证分数。对于非常低的 gamma 值,您会发现训练分数和验证分数都很低。这被称为欠拟合。中等的 gamma 值将导致两个分数都很高,即分类器表现相当好。如果 gamma 值过高,分类器将会过拟合,这意味着训练分数很好但验证分数很差。 .. GENERATED FROM PYTHON SOURCE LINES 9-35 .. image-sg:: /auto_examples/model_selection/images/sphx_glr_plot_validation_curve_001.png :alt: Validation Curve for SVM with an RBF kernel :srcset: /auto_examples/model_selection/images/sphx_glr_plot_validation_curve_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from sklearn.datasets import load_digits from sklearn.model_selection import ValidationCurveDisplay from sklearn.svm import SVC X, y = load_digits(return_X_y=True) subset_mask = np.isin(y, [1, 2]) # binary classification: 1 vs 2 X, y = X[subset_mask], y[subset_mask] disp = ValidationCurveDisplay.from_estimator( SVC(), X, y, param_name="gamma", param_range=np.logspace(-6, -1, 5), score_type="both", n_jobs=2, score_name="Accuracy", ) disp.ax_.set_title("Validation Curve for SVM with an RBF kernel") disp.ax_.set_xlabel(r"gamma (inverse radius of the RBF kernel)") disp.ax_.set_ylim(0.0, 1.1) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.965 seconds) .. _sphx_glr_download_auto_examples_model_selection_plot_validation_curve.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/model_selection/plot_validation_curve.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_validation_curve.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_validation_curve.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_validation_curve.zip ` .. include:: plot_validation_curve.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_