问题描述
最近,我一直致力于在带有 Tensorflow 后端的 Keras 中应用网格搜索交叉验证 (sklearn GridSearchCV) 进行超参数调整.我的模型调整好后我正在尝试保存 GridSearchCV 对象以供以后使用,但没有成功.
Lately, I have been working on applying grid search cross validation (sklearn GridSearchCV) for hyper-parameter tuning in Keras with Tensorflow backend. An soon as my model is tuned I am trying to save the GridSearchCV object for later use without success.
超参数调优如下:
备注:create_keras_model 函数初始化并编译一个 Keras Sequential 模型.
Remark: create_keras_model function initializes and compiles a Keras Sequential model.
执行交叉验证后,我尝试使用以下代码保存网格搜索对象 (gs):
After the cross validation is performed I am trying to save the grid search object (gs) with the following code:
我得到的错误如下:
能否请您告诉我此错误的原因可能是什么?
Could you please let me know what might be the reason for this error?
谢谢!
P.S.:joblib.dump 方法适用于保存使用的 GridSearchCV 对象用于训练来自 sklearn 的 MLPRegressors.
P.S.: joblib.dump method works well for saving GridSearchCV objects that are used for the training MLPRegressors from sklearn.
推荐答案
使用
直接导入joblib
而不是
从 sklearn.externals 导入作业库
保存对象或结果:
joblib.dump(gs, 'model_file_name.pkl')
并使用以下方法加载您的结果:
and load your results using:
joblib.load("model_file_name.pkl")
这是一个简单的工作示例:
Here is a simple working example:
这篇关于如何保存 GridSearchCV 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!