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).