AttributeError: Can’t pickle local object ‘SOME_OBJECT_OR_FUNC’

I met this error when I tried to use GridSearchCV to find best hyper-parameter.
I checked my configuration and found when I set the parameter n_jobs to -1 which means run parallelly, it will throw out this error.

gs = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=1, cv=cv)

It seems that when using multiprocessing to run estimator parallely, the pickle cannot serialize the object(e.g nested function).

Can’t pickle nested function in FeatureExtracter
Python: pickling nested functions

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据