-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[WIP] Gaussian Process-based hyper-parameter optimization #5491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e371ee8
Initial gp-based hyperopt code
sds-dubois 9cefcc9
Rewrite gp_search based on spearmint
MechCoder 33eb4c7
please pass
MechCoder ac46f6b
Rewrite example
MechCoder bb57b6e
Refactor acquisition_func
MechCoder 949649b
Compute local searches in parallel
MechCoder a997535
Add param_distributions documenation
MechCoder ef1a704
update doc
MechCoder 9439dfb
Add option to search without sampling
MechCoder 8121d0a
fix
MechCoder 027a9b7
fix
MechCoder 5d88ece
Add strategy for sampling
MechCoder 3e61dbb
fix maxiter
MechCoder 50a927e
Add TODO
MechCoder d3b6105
FIX Joblib parallel handling
MechCoder 7c9b379
Speed up sampling
MechCoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
================================================================== | ||
Plotting Performance of different hyperparameter selection methods | ||
================================================================== | ||
|
||
In this plot you can see the validation scores of a Ridge regression model | ||
along steps of different hyperparameter selection methods. | ||
""" | ||
print(__doc__) | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
import numpy as np | ||
from scipy import stats | ||
|
||
from sklearn.model_selection import SequentialSearchCV | ||
from sklearn.model_selection import GridSearchCV | ||
from sklearn.model_selection import RandomizedSearchCV | ||
from sklearn.linear_model import Ridge, LogisticRegression | ||
from sklearn.datasets import load_iris, make_classification, load_digits | ||
from sklearn.gaussian_process.kernels import Matern | ||
|
||
|
||
# Make synthetic dataset where not all the features are explanatory | ||
# iris = load_iris() | ||
# rng = np.random.RandomState(0) | ||
# X, y = iris.data, iris.target | ||
digits = load_digits() | ||
X, y = digits.data, digits.target | ||
|
||
clf = LogisticRegression() | ||
|
||
params = {'C': {'bounds': [10**-3, 10**3], 'scale': 'log'}} | ||
|
||
# Run SequentialSearch with first 5 iterations random. | ||
gp_search = SequentialSearchCV( | ||
clf, params, n_iter=20, random_state=0, n_init=3) | ||
gp_search.fit(X, y) | ||
|
||
# Retrieve the maximum score at each iteration | ||
gp_cum_scores = [np.max( | ||
[gp_search.grid_scores_[j].mean_validation_score for j in range(i)]) | ||
for i in range(1, len(gp_search.grid_scores_))] | ||
|
||
gp_ext = SequentialSearchCV( | ||
clf, params, n_iter=20, random_state=0, n_init=3, search='extensive') | ||
gp_ext.fit(X, y) | ||
|
||
# Retrieve the maximum score at each iteration | ||
gp_ext_cum_scores = [np.max( | ||
[gp_ext.grid_scores_[j].mean_validation_score for j in range(i)]) | ||
for i in range(1, len(gp_ext.grid_scores_))] | ||
|
||
|
||
# Do the same experiment with randomized search cv | ||
params = {'C': stats.expon(scale=10**-1)} | ||
rdm_search = RandomizedSearchCV( | ||
clf, params, random_state=0, n_iter=20) | ||
rdm_search.fit(X, y) | ||
|
||
rdm_cum_scores = [np.max( | ||
[rdm_search.grid_scores_[j].mean_validation_score for j in range(i)]) | ||
for i in range(1, len(rdm_search.grid_scores_))] | ||
|
||
# Do a standard grid search across pre-defined parameters. | ||
params = {'C': np.logspace(-3, 3, 20)} | ||
|
||
grid_search = GridSearchCV(clf, params) | ||
grid_search.fit(X, y) | ||
|
||
grid_cum_scores = [np.max( | ||
[grid_search.grid_scores_[j].mean_validation_score for j in range(i)]) | ||
for i in range(1, len(grid_search.grid_scores_))] | ||
|
||
plt.plot(gp_cum_scores, label='GP local', lw=3) | ||
plt.plot(rdm_cum_scores, label='Random Search', lw=3) | ||
plt.plot(grid_cum_scores, label='Grid Search', lw=3) | ||
plt.plot(gp_ext_cum_scores, label='GP ext', lw=3) | ||
|
||
plt.legend(loc='lower right') | ||
plt.ylabel('Score (higher is better)') | ||
plt.xlabel('Number of model evaluations') | ||
plt.show() |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MechCoder add yourself to this list. Also, the correct reference is now
SequentialSearchCV