TST: More thorough checks for Python tests
This commit is contained in:
parent
82a43f448e
commit
8196d5d680
@ -6,13 +6,15 @@ dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train')
|
|||||||
dtest = xgb.DMatrix(dpath + 'agaricus.txt.test')
|
dtest = xgb.DMatrix(dpath + 'agaricus.txt.test')
|
||||||
|
|
||||||
def test_glm():
|
def test_glm():
|
||||||
param = {'silent':1, 'objective':'binary:logistic', 'booster':'gblinear',
|
param = {'silent':1, 'objective':'binary:logistic', 'booster':'gblinear', 'alpha': 0.0001, 'lambda': 1 }
|
||||||
'alpha': 0.0001, 'lambda': 1 }
|
|
||||||
watchlist = [(dtest,'eval'), (dtrain,'train')]
|
watchlist = [(dtest,'eval'), (dtrain,'train')]
|
||||||
num_round = 4
|
num_round = 4
|
||||||
bst = xgb.train(param, dtrain, num_round, watchlist)
|
bst = xgb.train(param, dtrain, num_round, watchlist)
|
||||||
|
assert isinstance(bst, xgb.core.Booster)
|
||||||
preds = bst.predict(dtest)
|
preds = bst.predict(dtest)
|
||||||
labels = dtest.get_label()
|
labels = dtest.get_label()
|
||||||
|
err = sum(1 for i in range(len(preds)) if int(preds[i]>0.5)!=labels[i]) / float(len(preds))
|
||||||
|
assert err < 0.1
|
||||||
|
|
||||||
def test_custom_objective():
|
def test_custom_objective():
|
||||||
param = {'max_depth':2, 'eta':1, 'silent':1 }
|
param = {'max_depth':2, 'eta':1, 'silent':1 }
|
||||||
@ -28,5 +30,10 @@ def test_custom_objective():
|
|||||||
labels = dtrain.get_label()
|
labels = dtrain.get_label()
|
||||||
return 'error', float(sum(labels != (preds > 0.0))) / len(labels)
|
return 'error', float(sum(labels != (preds > 0.0))) / len(labels)
|
||||||
bst = xgb.train(param, dtrain, num_round, watchlist, logregobj, evalerror)
|
bst = xgb.train(param, dtrain, num_round, watchlist, logregobj, evalerror)
|
||||||
|
assert isinstance(bst, xgb.core.Booster)
|
||||||
|
preds = bst.predict(dtest)
|
||||||
|
labels = dtest.get_label()
|
||||||
|
err = sum(1 for i in range(len(preds)) if int(preds[i]>0.5)!=labels[i]) / float(len(preds))
|
||||||
|
assert err < 0.1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user