按照sklearn的教程,我尝试保存通过 sklearn 创建但未成功的对象。看来问题出在交叉验证对象上,因为我可以保存实际(最终)模型。
鉴于:
rf_model = RandomForestRegressor(n_estimators=1000, n_jobs=4, compute_importances = False)
cvgridsrch = GridSearchCV(estimator=rf_model, param_grid=parameters,n_jobs=4)
cvgridsrch.fit(X,y)
这将成功:
joblib.dump(cvgridsrch.best_estimator_, 'C:\\Users\\Desktop\\DMA\\cvgridsrch.pkl', compress=9)
这将失败:
joblib.dump(cvgridsrch, 'C:\\Users\\Desktop\\DMA\\cvgridsrch.pkl', compress=9)
有错误:
PicklingError: Can't pickle <type 'instancemethod'>: it's not found as __builtin__.instancemethod
如何保存完整的对象?