Added assertions for classification tests
This commit is contained in:
parent
3dbd4af263
commit
d20bfb12e4
@ -16,9 +16,10 @@ def test_binary_classification():
|
|||||||
kf = KFold(y.shape[0], n_folds=2, shuffle=True, random_state=rng)
|
kf = KFold(y.shape[0], n_folds=2, shuffle=True, random_state=rng)
|
||||||
for train_index, test_index in kf:
|
for train_index, test_index in kf:
|
||||||
xgb_model = xgb.XGBClassifier().fit(X[train_index],y[train_index])
|
xgb_model = xgb.XGBClassifier().fit(X[train_index],y[train_index])
|
||||||
predictions = xgb_model.predict(X[test_index])
|
preds = xgb_model.predict(X[test_index])
|
||||||
actuals = y[test_index]
|
labels = y[test_index]
|
||||||
print(confusion_matrix(actuals, predictions))
|
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_multiclass_classification():
|
def test_multiclass_classification():
|
||||||
iris = load_iris()
|
iris = load_iris()
|
||||||
@ -27,10 +28,10 @@ def test_multiclass_classification():
|
|||||||
kf = KFold(y.shape[0], n_folds=2, shuffle=True, random_state=rng)
|
kf = KFold(y.shape[0], n_folds=2, shuffle=True, random_state=rng)
|
||||||
for train_index, test_index in kf:
|
for train_index, test_index in kf:
|
||||||
xgb_model = xgb.XGBClassifier().fit(X[train_index],y[train_index])
|
xgb_model = xgb.XGBClassifier().fit(X[train_index],y[train_index])
|
||||||
predictions = xgb_model.predict(X[test_index])
|
preds = xgb_model.predict(X[test_index])
|
||||||
actuals = y[test_index]
|
labels = y[test_index]
|
||||||
print(confusion_matrix(actuals, predictions))
|
err = sum(1 for i in range(len(preds)) if int(preds[i]>0.5)!=labels[i]) / float(len(preds))
|
||||||
|
assert err < 0.3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user