Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <[email protected]>
  • Loading branch information
xadupre committed May 22, 2024
1 parent 05f76b9 commit fe83d7a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions onnxmltools/utils/tests_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ def dump_data_and_model(
os.makedirs(folder)

if hasattr(model, "predict"):
import lightgbm
import xgboost

if isinstance(model, lightgbm.Booster):
try:
import lightgbm
except ImportError:
lightgbm = None
try:
import xgboost
except ImportError:
xgboost = None

if lightgbm is not None and isinstance(model, lightgbm.Booster):
# LightGBM Booster
model_dict = model.dump_model()
if model_dict["objective"].startswith("binary"):
Expand All @@ -105,7 +111,7 @@ def dump_data_and_model(
prediction = [score.argmax(axis=1), score]
else:
prediction = [model.predict(data)]
elif isinstance(model, xgboost.Booster):
elif xgboost is not None and isinstance(model, xgboost.Booster):
# XGBoost Booster
from ..convert.xgboost._parse import _get_attributes
from xgboost import DMatrix
Expand Down

0 comments on commit fe83d7a

Please sign in to comment.