-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for LightGBM and XGBoost
- Loading branch information
1 parent
6cec035
commit 5400dc8
Showing
8 changed files
with
141 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import io | ||
import os | ||
|
||
from blazee.utils import (SerializedModel, add_file_deps, | ||
get_files_dependencies, get_requirements) | ||
|
||
|
||
def is_lightgbm(model): | ||
try: | ||
from lightgbm.basic import Booster | ||
return isinstance(model, Booster) | ||
except: | ||
return False | ||
|
||
|
||
def _get_model_metadata(model, include_files): | ||
deps = ['lightgbm'] | ||
return { | ||
'lib_versions': get_requirements(deps), | ||
'include_files': include_files | ||
} | ||
|
||
|
||
def serialize_lightgbm(model, include_files): | ||
tmp_file = 'tmp.txt' | ||
try: | ||
model.save_model(tmp_file) | ||
with open(tmp_file, 'rb') as f: | ||
buffer = f.read() | ||
finally: | ||
try: | ||
os.remove(tmp_file) | ||
except OSError: | ||
pass | ||
|
||
files = [('model.txt', buffer)] | ||
|
||
add_file_deps(files, include_files) | ||
|
||
meta = _get_model_metadata(model, include_files) | ||
|
||
return SerializedModel('lightgbm', meta, files) |
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,42 @@ | ||
import io | ||
import os | ||
|
||
from blazee.utils import (SerializedModel, add_file_deps, | ||
get_files_dependencies, get_requirements) | ||
|
||
|
||
def is_xgboost(model): | ||
try: | ||
from xgboost.core import Booster | ||
return isinstance(model, Booster) | ||
except: | ||
return False | ||
|
||
|
||
def _get_model_metadata(model, include_files): | ||
deps = ['xgboost'] | ||
return { | ||
'lib_versions': get_requirements(deps), | ||
'include_files': include_files | ||
} | ||
|
||
|
||
def serialize_xgboost(model, include_files): | ||
tmp_file = 'tmp.txt' | ||
try: | ||
model.save_model(tmp_file) | ||
with open(tmp_file, 'rb') as f: | ||
buffer = f.read() | ||
finally: | ||
try: | ||
os.remove(tmp_file) | ||
except OSError: | ||
pass | ||
|
||
files = [('model.txt', buffer)] | ||
|
||
add_file_deps(files, include_files) | ||
|
||
meta = _get_model_metadata(model, include_files) | ||
|
||
return SerializedModel('xgboost', meta, files) |