pickle.load: ImportError: No module named k_means_
<p>I'm dumping a <code>sklearn.cluster.KMeans</code> object using <code>pickle</code> like this:</p>

<pre><code>kmeans = KMeans(n_clusters=7)

kmeans.fit(X)

pickle.dump(kmeans, open(model_fname, "w"), protocol=2)
</code></pre>

<p>However, if I try to reload this pickle file:</p>

<pre><code>if os.path.exists(model_fname):
    print "Loading existing model .."
    return pickle.load(open(model_fname, "rb"))
</code></pre>

<p>I'm getting:</p>

<pre><code>  File "C:\Python27\lib\pickle.py", line 1130, in find_class
    __import__(module)
ImportError: No module named k_means_
</code></pre>

<p>How can I load this file?</p>

<p>I just replaced <code>pickle</code> by <code>joblib</code>:</p>

<pre><code>from sklearn.externals import joblib
</code></pre>

python scikit-learn pickle