Last active
August 29, 2015 14:03
-
-
Save ogrisel/dab225fc9d0a365119b6 to your computer and use it in GitHub Desktop.
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 sklearn | |
from sklearn.linear_model import SGDClassifier | |
from sklearn import grid_search | |
print("numpy:", np.__version__) | |
print("sklearn:", sklearn.__version__) | |
n_samples = 100000 | |
n_features = 5000 | |
X_train = np.random.randn(n_samples, n_features) | |
y_train = np.random.randint(0, 2, size=n_samples) | |
print("input data size: %.3fMB" % (X_train.nbytes / 1e6)) | |
model = SGDClassifier(penalty='elasticnet', n_iter=10, shuffle=True) | |
param_grid = [{ | |
'alpha' : 10.0 ** -np.arange(1, 7), | |
'l1_ratio': [.05, .5, .9, 1], | |
}] | |
if __name__ == "__main__": | |
gs = grid_search.GridSearchCV(model, param_grid, n_jobs=8, verbose=100) | |
gs.fit(X_train, y_train) | |
print(gs.best_params_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment