[英]How to store model to hdfs using python
我正在嘗試使用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”對象沒有屬性“ startswith”
然后我嘗試使用pickle選項
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.