Skip to content

Instantly share code, notes, and snippets.

@amueller
Created April 10, 2012 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amueller/2354823 to your computer and use it in GitHub Desktop.
Save amueller/2354823 to your computer and use it in GitHub Desktop.
scale_c test
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.cross_validation import ShuffleSplit
from sklearn.grid_search import GridSearchCV
from sklearn import datasets
n_samples = 100
n_features = 1000
X, y = datasets.make_classification(n_samples=n_samples, n_features=n_features,
n_informative=5, random_state=1)
for train_fraction in np.arange(0.1, 0.6, 0.1):
svm = LinearSVC(penalty='L1', dual=False, scale_C=True)
cs = 2. ** np.arange(-15, 15)
param_grid = dict(C=cs)
grid = GridSearchCV(svm, param_grid=param_grid,
cv=ShuffleSplit(n=n_samples, train_fraction=train_fraction,
n_iterations=100, random_state=1))
grid.fit(X, y)
scores = [x[1] for x in grid.grid_scores_]
plt.plot(np.arange(-15, 15), scores, label="fraction %.2f" %
train_fraction)
print(svm)
plt.legend(loc="best")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment