.. 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 JupyterLite or Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_model_selection_plot_validation_curve.py: ========================== Plotting Validation Curves ========================== In this plot you can see the training scores and validation scores of an SVM for different values of the kernel parameter gamma. For very low values of gamma, you can see that both the training score and the validation score are low. This is called underfitting. Medium values of gamma will result in high values for both scores, i.e. the classifier is performing fairly well. If gamma is too high, the classifier will overfit, which means that the training score is good but the validation score is poor. .. GENERATED FROM PYTHON SOURCE LINES 15-41 .. 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 1.020 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:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../lite/lab/?path=auto_examples/model_selection/plot_validation_curve.ipynb :alt: Launch JupyterLite :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 ` .. include:: plot_validation_curve.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_