-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Add Dart booster. #1220
Merged
Merged
Add Dart booster. #1220
Changes from all commits
Commits
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 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
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 |
---|---|---|
|
@@ -23,6 +23,51 @@ def test_glm(self): | |
if int(preds[i] > 0.5) != labels[i]) / float(len(preds)) | ||
assert err < 0.1 | ||
|
||
def test_dart(self): | ||
dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train') | ||
dtest = xgb.DMatrix(dpath + 'agaricus.txt.test') | ||
param = {'max_depth': 5, 'objective': 'binary:logistic', 'booster': 'dart', 'silent': False} | ||
# specify validations set to watch performance | ||
watchlist = [(dtest, 'eval'), (dtrain, 'train')] | ||
num_round = 2 | ||
bst = xgb.train(param, dtrain, num_round, watchlist) | ||
# this is prediction | ||
preds = bst.predict(dtest, ntree_limit=num_round) | ||
labels = dtest.get_label() | ||
err = sum(1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i]) / float(len(preds)) | ||
# error must be smaller than 10% | ||
assert err < 0.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us add a few testcase with the parameters you proposed, e.g. normalize type |
||
|
||
# save dmatrix into binary buffer | ||
dtest.save_binary('dtest.buffer') | ||
# save model | ||
bst.save_model('xgb.model.dart') | ||
# load model and data in | ||
bst2 = xgb.Booster(params=param, model_file='xgb.model.dart') | ||
dtest2 = xgb.DMatrix('dtest.buffer') | ||
preds2 = bst2.predict(dtest2, ntree_limit=num_round) | ||
# assert they are the same | ||
assert np.sum(np.abs(preds2 - preds)) == 0 | ||
|
||
# check whether sample_type and normalize_type work | ||
num_round = 50 | ||
param['silent'] = True | ||
param['learning_rate'] = 0.1 | ||
param['rate_drop'] = 0.1 | ||
preds_list = [] | ||
for p in [[p0, p1] for p0 in ['uniform', 'weighted'] for p1 in ['tree', 'forest']]: | ||
param['sample_type'] = p[0] | ||
param['normalize_type'] = p[1] | ||
bst = xgb.train(param, dtrain, num_round, watchlist) | ||
preds = bst.predict(dtest, ntree_limit=num_round) | ||
err = sum(1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i]) / float(len(preds)) | ||
assert err < 0.1 | ||
preds_list.append(preds) | ||
|
||
for ii in range(len(preds_list)): | ||
for jj in range(ii + 1, len(preds_list)): | ||
assert np.sum(np.abs(preds_list[ii] - preds_list[jj])) > 0 | ||
|
||
def test_eta_decay(self): | ||
watchlist = [(dtest, 'eval'), (dtrain, 'train')] | ||
num_round = 4 | ||
|
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.
is this same as the GBTre except the drop trees? Would be better to leave a comment here