我正在尝试使用 python 将我的模型存储到 hdfs。
这段代码是使用pydoop库
import pydoop.hdfs as hdfs
from_path = prediction_model.fit(orginal_telecom_80p_train[features], orginal_telecom_80p_train["Churn"])
to_path ='hdfs://192.168.1.101:8020/user/volumata/python_models/churn_model.sav'
hdfs.put(from_path, to_path)
但是,在使用这个的时候,我得到了这个错误
AttributeError: 'LogisticRegression' object has no attribute 'startswith'
然后我尝试使用泡菜选项
import pickle
with open('hdfs://192.168.1.101:8020/user/volumata/python_models/') as hdfs_loc:
pickle.dump(prediction_model, hdfs_loc)
Pickle 选项在本地工作正常,当我尝试将模型存储在 hdfs 中时,此选项对我也不起作用。谁能建议如何使用 python 脚本进一步将模型存储到 hdfs?
最佳答案
您必须使用hdfs.open
而不是open
,并打开文件进行写入:
import pickle
import pydoop.hdfs as hdfs
with hdfs.open(to_path, 'w') as f:
pickle.dump(prediction_model, f)
关于python - 如何使用python将模型存储到hdfs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49940930/