-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Don't set_params at the end of set_state. * Also fix another issue found in dask prediction. * Add note about prediction. Don't support other prediction modes at the moment.
- Loading branch information
1 parent
2ebdec8
commit 7e72a12
Showing
6 changed files
with
70 additions
and
8 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pickle | ||
import numpy as np | ||
import xgboost as xgb | ||
import os | ||
|
||
|
||
kRows = 100 | ||
kCols = 10 | ||
|
||
|
||
def generate_data(): | ||
X = np.random.randn(kRows, kCols) | ||
y = np.random.randn(kRows) | ||
return X, y | ||
|
||
|
||
def test_model_pickling(): | ||
xgb_params = { | ||
'verbosity': 0, | ||
'nthread': 1, | ||
'tree_method': 'hist' | ||
} | ||
|
||
X, y = generate_data() | ||
dtrain = xgb.DMatrix(X, y) | ||
bst = xgb.train(xgb_params, dtrain) | ||
|
||
dump_0 = bst.get_dump(dump_format='json') | ||
assert dump_0 | ||
|
||
filename = 'model.pkl' | ||
|
||
with open(filename, 'wb') as fd: | ||
pickle.dump(bst, fd) | ||
|
||
with open(filename, 'rb') as fd: | ||
bst = pickle.load(fd) | ||
|
||
with open(filename, 'wb') as fd: | ||
pickle.dump(bst, fd) | ||
|
||
with open(filename, 'rb') as fd: | ||
bst = pickle.load(fd) | ||
|
||
assert bst.get_dump(dump_format='json') == dump_0 | ||
|
||
if os.path.exists(filename): | ||
os.remove(filename) |
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