我用pickle
倾倒一个sklearn.cluster.KMeans
对象,像这样:
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:Python27libpickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named k_means_
如何加载这个文件?
我刚刚用joblib
代替了pickle
:
from sklearn.externals import joblib