-
Notifications
You must be signed in to change notification settings - Fork 101
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
Fix loading latest XGBoost binary model. #144
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,28 @@ def test_xgb_iris(self): | |
assert predictor.pred_transform == 'max_index' | ||
assert predictor.global_bias == 0.5 | ||
assert predictor.sigmoid_alpha == 1.0 | ||
|
||
def test_logistic(self): | ||
np.random.seed(0) | ||
kRows = 16 | ||
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. Is there a similar test for the exponential families? You could parametrize and reuse this with just a different randint limit for count:poisson probably. 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. Adding it. |
||
kCols = 8 | ||
X = np.random.randn(kRows, kCols) | ||
y = np.random.randint(0, 2, size=kRows) | ||
assert y.min() == 0 | ||
assert y.max() == 1 | ||
|
||
dtrain = xgboost.DMatrix(X, y) | ||
booster = xgboost.train({'objective': 'binary:logistic'}, dtrain=dtrain, | ||
num_boost_round=4) | ||
expected_pred = booster.predict(dtrain) | ||
model = treelite.Model.from_xgboost(booster) | ||
libpath = libname('./logistic{}') | ||
batch = treelite.runtime.Batch.from_npy2d(X) | ||
for toolchain in os_compatible_toolchains(): | ||
model.export_lib(toolchain=toolchain, libpath=libpath, | ||
params={}, verbose=True) | ||
predictor = treelite.runtime.Predictor(libpath=libpath, verbose=True) | ||
out_pred = predictor.predict(batch) | ||
assert_almost_equal(out_pred, expected_pred) | ||
assert predictor.num_feature == kCols | ||
assert predictor.global_bias == 0 |
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.
do we need to do something special for
survival:cox
? or assert that it is not supported?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.
No, it is not necessary, since the label is not in log scale for
survival:cox
. Forsurvival:cox
, the convention is to use negative label to represent right-censored data.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.
@hcho3 has better understanding of survival model than me.