当我尝试加载LightGBM模型时,会出现分段故障。我尝试过pickle(包括协议更改(、cloudpickle、joblib和lightGBM save_model,但无法加载这些模型。
保存型号:
model = lgb.LGBMRegressor(**kargs)
model.fit(self.X_train, self.y_train)
with open(self.output_dir + 'models.pkl', "wb") as f:
pickle.dump(model, f, protocol=4)
with open(self.output_dir + 'modelcl.pkl', "wb") as f:
f.write(cloudpickle.dumps(model))
pickle.dump(model, open(self.output_dir +
'model.pkl', 'wb'), protocol=4)
joblib.dump(model, f'{self.output_dir}model.joblib')
joblib.dump(model, f'{self.output_dir}model.xz', compress=True)
model.booster_.save_model(f'{self.output_dir}model.txt')
负载型号:
joblib.load('path/model.xz')
joblib.load('path/model.joblib')
pickle.load(open('path/models.pkl', 'rb'))
pickle.load(open('path/modelcl.pkl', 'rb'))
pickle.load(open('path/model.pkl', 'rb'))
model = lgb.Booster(model_file='path/model.txt')
环境:M1 Mac Monterely(12.0.1(Python 3.8.12(conda(,joblib==1.1.0,lightgbm==3.3.2。
你知道这里发生了什么吗?我想我应该试着保存权重,而不是保存整个模型,但我不知道如何使用LightGBM。
通过从condaconda install -c conda-forge lightgbm
安装lightgbm而不是使用pip install lightgbm
解决了此问题。可能不建议从pip安装lightgbm。
已安装的软件包conda-forge/osx-arm64::lightgbm-3.3.2-py38hb2dfaa5_0
资源:https://lightgbm.readthedocs.io/en/latest/FAQ.html#i-遇到分段故障使用pip-install-lightgbm 从pypi安装lightgbm后随机出现分段故障