-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a max_samples parameter to grid search for benchmarking purpose…
…s, adjusted the grid search script respectively
- Loading branch information
1 parent
efbc966
commit fc44944
Showing
4 changed files
with
34 additions
and
13 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import numpy as np | ||
import xgboost as xgb | ||
from sklearn.model_selection import GridSearchCV | ||
|
||
from tuning import util | ||
|
||
|
||
def run(data, cv): | ||
def run(data, max_samples, cv): | ||
search = GridSearchCV( | ||
estimator=xgb.XGBClassifier(n_jobs=-1), | ||
param_grid=util.param_grid, | ||
estimator=xgb.XGBClassifier(n_jobs=-1, n_estimators=10), | ||
param_grid=_generate_grid(max_samples), | ||
scoring='roc_auc', | ||
n_jobs=-1, | ||
verbose=2, | ||
verbose=1, | ||
cv=cv | ||
) | ||
|
||
search.fit(data['X'], data['y']) | ||
|
||
return [search.best_score_, search.best_params_] | ||
|
||
|
||
def _generate_grid(max_samples): | ||
generated_grid = {} | ||
|
||
for param, dist in util.param_distributions.items(): | ||
generated_grid[param] = [] | ||
num_samples = np.random.randint(1, max_samples + 1) | ||
|
||
if isinstance(dist, list): | ||
generated_grid[param].extend(np.random.choice(dist, size=num_samples)) | ||
else: | ||
for i in range(num_samples): | ||
generated_grid[param].append(dist.rvs()) | ||
|
||
return generated_grid |
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
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