我正在使用sklearn.cluster.KMeans
转储pickle
对象:
kmeans = KMeans(n_clusters=7)
kmeans.fit(X)
pickle.dump(kmeans, open(model_fname, "w"), protocol=2)
但是,如果我尝试重新加载这个pickle文件:
if os.path.exists(model_fname):
print "Loading existing model .."
return pickle.load(open(model_fname, "rb"))
我得到了:
File "C:\Python27\lib\pickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named k_means_
如何加载此文件?
答案 0 :(得分:2)
我刚刚将pickle
替换为joblib
:
from sklearn.externals import joblib