pickle.load:ImportError:没有名为k_means_的模块

时间:2016-10-02 15:59:20

标签: python scikit-learn pickle

我正在使用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_

如何加载此文件?

1 个答案:

答案 0 :(得分:2)

我刚刚将pickle替换为joblib

from sklearn.externals import joblib