<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 SVC Cross Validtion Scores vs C-value
The goal here is to visualize the effect of the C parameter (the amount of regularization penalty to use) on a Support Vector Classifier when classifying samples from the digits dataset. I'm going to use 10-fold cross validation and the cross_val_score function to get the scores then plot them with matplotlib.
Step1:  The data
Step2:  Set up 10 Folds Cross Validation
Step3:  Set up the logarithmic C-values
Step4:  Set up the linear Support Vector Classifier
Step5:  Get cross-validation scroes for each C-value
Step6:  Plot the mean-scores and standard deviations.
Step7:  It looks like the default does well as the best model that I found by changing the C-values, even though it is set to 1.
looking at it without the log-plotting
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plot
import seaborn
from sklearn import datasets
from sklearn import svm
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
%matplotlib inline
Explanation: SVC Cross Validtion Scores vs C-value
The goal here is to visualize the effect of the C parameter (the amount of regularization penalty to use) on a Support Vector Classifier when classifying samples from the digits dataset. I'm going to use 10-fold cross validation and the cross_val_score function to get the scores then plot them with matplotlib.
End of explanation
digits = datasets.load_digits()
print(digits.DESCR)
Explanation: The data
End of explanation
k_folds = KFold(n_splits=10)
Explanation: Set up 10 Folds Cross Validation
End of explanation
c_values = numpy.logspace(-10, 0, 10)
Explanation: Set up the logarithmic C-values
End of explanation
model = svm.SVC(kernel='linear')
Explanation: Set up the linear Support Vector Classifier
End of explanation
scores = [cross_val_score(model.set_params(C=c_value),
                          digits.data,
                          digits.target,
                          cv=k_folds,
                          n_jobs=-1) for c_value in c_values]
Explanation: Get cross-validation scroes for each C-value
End of explanation
means = numpy.array([numpy.mean(score) for score in scores])
deviations = numpy.array([numpy.std(score) for score in scores])
seaborn.set_style("whitegrid")
figure = plot.figure()
axe = figure.gca()
line = plot.plot(c_values, means, axes=axe)
line = plot.plot(c_values, means + deviations, '--')
line = plot.plot(c_values, means - deviations, '--')
title = axe.set_title("Accuracy vs C")
label = axe.set_ylabel("Accuracy")
labels = axe.set_ylabel("C Value")
axe.set_xscale('log')
best_index = means.argmax()
best_c = c_values[means.argmax()]
best_mean = means[best_index]
best_std = deviations[best_index]
print("Best C-value: {0:.5f}".format(best_c))
print("95% Confidence Interval for Accuracy: ({0:.2f} +/- {1:.2f})".format(best_mean,
                                                                           best_std))
model = svm.SVC(kernel="linear")
scores = cross_val_score(model, digits.data, digits.target, cv=k_folds, n_jobs=-1)
mean = numpy.mean(scores)
std = numpy.std(scores)
print("95% Confidence Interval for accuracy of default C-value: ({0:.2f} +/- {1:.2f})".format(mean, std))
best_mean - mean
model.C
Explanation: Plot the mean-scores and standard deviations.
End of explanation
c_values = numpy.linspace(0, 1)[1:]
scores = [cross_val_score(model.set_params(C=c_value),
                          digits.data,
                          digits.target,
                          cv=k_folds,
                          n_jobs=-1) for c_value in c_values]
means = numpy.array([numpy.mean(score) for score in scores])
deviations = numpy.array([numpy.std(score) for score in scores])
seaborn.set_style("whitegrid")
figure = plot.figure()
axe = figure.gca()
line = plot.plot(c_values, means, axes=axe)
line = plot.plot(c_values, means + deviations, '--')
line = plot.plot(c_values, means - deviations, '--')
title = axe.set_title("Accuracy vs C")
label = axe.set_ylabel("Accuracy")
labels = axe.set_ylabel("C Value")
Explanation: It looks like the default does well as the best model that I found by changing the C-values, even though it is set to 1.
looking at it without the log-plotting
End of explanation
<END_TASK>