I'm trying to save my model so it can be used in a ASP.NET program, and I think that ONNX is a good way to do so. The problem is that even after checking the docs and googling it all day, I still get the same error raise ValueError('Initial types are required. See usage of ' ValueError: Initial types are required. See usage of convert(...) in skl2onnx.convert for details
. I have no idea what's going on and any help is greatly appreciated!
My Code
import onnxmltools
from skl2onnx import convert
import lightgbm as lgb
import pandas as pd
parameters = {
'boosting': 'gbdt',
'feature_fraction': 0.5,
'bagging_fraction': 0.5,
'bagging_freq': 20,
'num_boost_round': 10000,
'verbose': -1 #maybe?
}
model_lgbm = lgb.train(parameters, train_data, valid_sets = test_data, early_stopping_rounds = 200);
onnx_model = convert.convert_sklearn(model_lgbm, ???);
CodePudding user response:
I think this doc will help you.
You have to use : onnxmltools.convert_lightgbm and not convert.convert_sklearn
CodePudding user response:
You can save your model using pickle:
import pickle
pickle.dump(model_lgbm,open("model_lgbm.pk", "wb" ))
and then you can load it whenever you need:
model = pickle.load(open('model_lgbm.pk','rb'))