Skip to content

Instantly share code, notes, and snippets.

@jnothman
Created May 22, 2013 00:47
Show Gist options
  • Save jnothman/5624440 to your computer and use it in GitHub Desktop.
Save jnothman/5624440 to your computer and use it in GitHub Desktop.
from sklearn import pipeline, grid_search, linear_model, feature_selection, decomposition, datasets, preprocessing
iris = datasets.load_iris()
clf = pipeline.Pipeline([
('scale', preprocessing.StandardScaler()),
('sel', feature_selection.SelectKBest()),
('clf', linear_model.ElasticNet(warm_start=False)),
])
param_grid = {'scale__with_std': [False, True],
'sel__k': [1,2,3,4],
'clf__alpha': [0.001, 0.01, 0.1, 1., 10.],
'clf__l1_ratio': [0.5, 1.0]}
search = grid_search.GridSearchCV(clf, param_grid=param_grid)
search.fit(iris.data, iris.target)
print(search.best_params_, search.best_score_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment