I created a pipeline in Azure ML that trains a model using Boosted Decision Tree Regression. From my understanding, the model is saved as data.ilearner
.
However, I am unable to convert this model into a model.pkl
format that can be loaded using joblib
.
Questions:
- How can I create a
model.pkl
file in Azure ML for a Boosted Decision Tree Regression model? - How can I convert
data.ilearner
tomodel.pkl
?
I attempted to use the following Python script to load and convert the model:
import lightgbm as lgb
import joblib
# Load the LightGBM model
model = lgb.Booster(model_file="data.ilearner")
# Save as a Pickle file
joblib.dump(model, "model.pkl")
But when running the script, I get the following error:
% python3 convert_to_model_pkl.py
[LightGBM] [Fatal] Unknown model format or submodel type in model file data.ilearner
Traceback (most recent call last):
File "/Users/tomasz.olchawa/ng/ml/convert_to_model_pkl.py", line 5, in <module>
model = lgb.Booster(model_file="data.ilearner")
File "/Users/tomasz.olchawa/ng/ml/myenv/lib/python3.13/site-packages/lightgbm/basic.py", line 3697, in __init__
_safe_call(
~~~~~~~~~~^
_LIB.LGBM_BoosterCreateFromModelfile(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
)
^
File "/Users/../ng/ml/myenv/lib/python3.13/site-packages/lightgbm/basic.py", line 313, in _safe_call
raise LightGBMError(_LIB.LGBM_GetLastError().decode("utf-8"))
lightgbm.basic.LightGBMError: Unknown model format or submodel type in model file data.ilearner
I created a pipeline in Azure ML that trains a model using Boosted Decision Tree Regression. From my understanding, the model is saved as data.ilearner
.
However, I am unable to convert this model into a model.pkl
format that can be loaded using joblib
.
Questions:
- How can I create a
model.pkl
file in Azure ML for a Boosted Decision Tree Regression model? - How can I convert
data.ilearner
tomodel.pkl
?
I attempted to use the following Python script to load and convert the model:
import lightgbm as lgb
import joblib
# Load the LightGBM model
model = lgb.Booster(model_file="data.ilearner")
# Save as a Pickle file
joblib.dump(model, "model.pkl")
But when running the script, I get the following error:
% python3 convert_to_model_pkl.py
[LightGBM] [Fatal] Unknown model format or submodel type in model file data.ilearner
Traceback (most recent call last):
File "/Users/tomasz.olchawa/ng/ml/convert_to_model_pkl.py", line 5, in <module>
model = lgb.Booster(model_file="data.ilearner")
File "/Users/tomasz.olchawa/ng/ml/myenv/lib/python3.13/site-packages/lightgbm/basic.py", line 3697, in __init__
_safe_call(
~~~~~~~~~~^
_LIB.LGBM_BoosterCreateFromModelfile(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
)
^
File "/Users/../ng/ml/myenv/lib/python3.13/site-packages/lightgbm/basic.py", line 313, in _safe_call
raise LightGBMError(_LIB.LGBM_GetLastError().decode("utf-8"))
lightgbm.basic.LightGBMError: Unknown model format or submodel type in model file data.ilearner
Share
Improve this question
edited Mar 2 at 17:16
desertnaut
60.5k32 gold badges155 silver badges182 bronze badges
asked Mar 1 at 12:45
THMTHM
6811 gold badge9 silver badges29 bronze badges
1
|
1 Answer
Reset to default 0- In Azure ML, after training, save the trained model using the Export Model module. If this option is not available, you may need to use Convert Model to ONNX and then convert it to a format suitable for scikit-learn.
Azure ML’s Boosted Decision Tree Regression model is typically in a proprietary format, so you'll need to extract it using Azure ML SDK
from azureml.core import Workspace, Model
import pickle
# Load the workspace
ws = Workspace.from_config()
# Get the registered model
model = Model(ws, name="your_model_name")
# Download the model (if needed)
model.download(target_dir="./", exist_ok=True)
# Load the model using joblib
with open("data.ilearner", "rb") as f:
trained_model = pickle.load(f)
# Save as a Pickle file
with open("model.pkl", "wb") as f:
pickle.dump(trained_model, f)
If Azure ML does not allow direct export to a pickle-compatible format, convert the model to ONNX in Azure ML. Convert ONNX to a scikit-learn model using onnxmltools
or skl2onnx
import onnx
from skl2onnx.helpers import load_model
import pickle
# Load the ONNX model
onnx_model = onnx.load("model.onnx")
# Convert ONNX model to scikit-learn model
sklearn_model = load_model(onnx_model)
# Save as a Pickle file
with open("model.pkl", "wb") as f:
pickle.dump(sklearn_model, f)
Azure ML’s data.ilearner
is not a LightGBM format. Once in scikit-learn format, you can use joblib.dump()
to save the model.
data.ilearner
tomodel.pkl
using theazureml.automl.runtime
package. Install it withpip install azureml-automl-runtime joblib
. then use this Now, model.pkl can be loaded using joblib.load("model.pkl"). – Suresh Chikkam Commented Mar 19 at 9:34