Skip to content

Commit

Permalink
Added test for maximize parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
terrytangyuan committed Nov 5, 2015
1 parent 8bf6525 commit 190e58a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/python/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def evalerror(preds, dtrain):
xgb.cv(param, dtrain, num_round, nfold = 5, seed = 0,
obj = logregobj, feval=evalerror)

# test maximize parameter
def neg_evalerror(preds, dtrain):
labels = dtrain.get_label()
return 'error', float(sum(labels == (preds > 0.0))) / len(labels)
bst2 = xgb.train(param, dtrain, num_round, watchlist, logregobj, neg_evalerror, maximize=True)
preds2 = bst2.predict(dtest)
err2 = sum(1 for i in range(len(preds2)) if int(preds2[i]>0.5)!=labels[i]) / float(len(preds2))
assert err == err2

def test_fpreproc(self):
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic'}
num_round = 2
Expand Down

0 comments on commit 190e58a

Please sign in to comment.