<jupyter_start><jupyter_text>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.  New to Plotly?Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).You can set up Plotly to work in [online](https://plot.ly/python/getting-started/initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/start-plotting-online).We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!  Version<jupyter_code>import sklearn
sklearn.__version__<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np
from sklearn.datasets import load_digits
from sklearn.svm import SVC
from sklearn.model_selection import validation_curve<jupyter_output><empty_output><jupyter_text>Calculations<jupyter_code>digits = load_digits()
X, y = digits.data, digits.target

param_range = np.logspace(-6, -1, 5)
train_scores, test_scores = validation_curve(
    SVC(), X, y, param_name="gamma", param_range=param_range,
    cv=10, scoring="accuracy", n_jobs=1)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)<jupyter_output><empty_output><jupyter_text>Plot Results<jupyter_code>layout = go.Layout(title="Validation Curve with SVM",
                      xaxis=dict(title="$\gamma$", type='log'),
                      yaxis=dict(title="Score"))

lw = 2
p1 = go.Scatter(x=param_range, y=train_scores_mean,
                name="Training score",
                mode='lines', 
                line=dict(color="orange", width=lw))

p2 = go.Scatter(x=param_range, y=train_scores_mean - train_scores_std,
                mode='lines', showlegend=False,
                line=dict(color="orange", width=1))

p3 = go.Scatter(x=param_range, y=train_scores_mean + train_scores_std,
                mode='lines', showlegend=False,
                line=dict(color="orange", width=1),
                fill='tonexty')

p4 = go.Scatter(x=param_range, y=test_scores_mean,
                name="Cross-validation score",
                mode='lines', 
                line=dict(color="navy", width=lw))

p5 = go.Scatter(x=param_range, y=test_scores_mean - test_scores_std,
                mode='lines', showlegend=False,
                line=dict(color="navy", width=1)) 

p6 = go.Scatter(x=param_range, y=test_scores_mean + test_scores_std,
                mode='lines', showlegend=False,
                line=dict(color="navy", width=1),
                fill='tonexty') 

fig = go.Figure(data=[p2, p3, p5, p6, p1, p4], layout=layout)
py.iplot(fig)
from IPython.display import display, HTML

display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))

! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
    'Validation Curves.ipynb', 'scikit-learn/plot-validation-curve/', 'Validation Curves | plotly',
    ' ',
    title = 'Validation Curves | plotly',
    name = 'Validation Curves',
    has_thumbnail='true', thumbnail='thumbnail/validation-curve.jpg', 
    language='scikit-learn', page_type='example_index',
    display_as='model_selection', order=1,
    ipynb= '~Diksha_Gabha/3406')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12581244196843083, 'fraction_numerical': 0.01160631383472609, 'mean_word_length': 4.254878048780488, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '526606', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1363, 'n_words': 303, 'path': '_posts/scikit/validation-curves/Validation Curves.ipynb', 'repo_name': 'bmb804/documentation', 'size': '4308'}