最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to Convert 'data.ilearner' Model to 'model.pkl' in Azure ML? - Stack Overflow

programmeradmin1浏览0评论

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:

  1. How can I create a model.pkl file in Azure ML for a Boosted Decision Tree Regression model?
  2. How can I convert data.ilearner to model.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:

  1. How can I create a model.pkl file in Azure ML for a Boosted Decision Tree Regression model?
  2. How can I convert data.ilearner to model.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
  • Convert data.ilearner to model.pkl using the azureml.automl.runtime package. Install it with pip 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
Add a comment  | 

1 Answer 1

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.

发布评论

评论列表(0)

  1. 暂无评论