DeepCoNN icon indicating copy to clipboard operation
DeepCoNN copied to clipboard

AttributeError: Can't pickle local object 'numerize.<locals>.<lambda>'

Open s1162276945 opened this issue 6 years ago • 3 comments

DeepCoNN/pro_data/loaddata.py 运行不了,报的是pickle 错误 print(item_reviews[11]) pickle.dump(user_reviews, open(os.path.join(TPS_DIR, 'user_review'), 'wb'))

s1162276945 avatar Jan 31 '18 13:01 s1162276945

in python3, you currently have to import dill as pickle https://stackoverflow.com/questions/25348532/can-python-pickle-lambda-functions

s1162276945 avatar May 28 '18 02:05 s1162276945

改成dill读取也是不行的,修改如下,把lambda换成apply就行了 def numerize(tp): # uid = map(lambda x: user2id[x], tp['user_id']) # sid = map(lambda x: item2id[x], tp['item_id']) tp['user_id'] = tp['user_id'].apply(lambda x:user2id[x]) tp['item_id'] = tp['item_id'].apply(lambda x:item2id[x]) return tp

Aliang-CN avatar Dec 06 '19 01:12 Aliang-CN

改成dill读取也是不行的,修改如下,把lambda换成apply就行了 def numerize(tp):

uid = map(lambda x: user2id[x], tp['user_id'])

sid = map(lambda x: item2id[x], tp['item_id'])

tp['user_id'] = tp['user_id'].apply(lambda x:user2id[x]) tp['item_id'] = tp['item_id'].apply(lambda x:item2id[x]) return tp

code: t.apply(lambda p: str(p.name)) for t in train_folders[0].glob("*.png") error: AttributeError: 'WindowsPath' object has no attribute 'apply' how to solve the error????

ITEliteCCY avatar Dec 09 '19 15:12 ITEliteCCY