Created
April 10, 2012 21:45
-
-
Save amueller/2354823 to your computer and use it in GitHub Desktop.
scale_c test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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