简体   繁体   中英

Error while executing scikit-learn K-means example

I'm trying to run a scikit-learn K-means example from scikit-learn official site: http://scikit-learn.org/dev/auto_examples/cluster/plot_cluster_iris.html#example-cluster-plot-cluster-iris-py

I got all libraries installed (eg, scipy, numpy, pylab). However, when executing the code, I got error message like this:

Traceback (most recent call last):
  File "plot_cluster_iris.py", line 41, in <module>
    estimators = {'k_means_iris_3': KMeans(n_clusters=3),
TypeError: __init__() got an unexpected keyword argument 'n_clusters'

Is it something to do with the scikit-learn version? I'm using ver. 0.11 on MAC OS X Lion.

You're looking at the docs for the bleeding edge development version of scikit-learn. The stable (0.11) version of that example is here . n_clusters will be introduced in 0.12, in older versions use k instead (though k will be around for some time for backward compatibility).

you need to upgrade sklern

for updating sklearn you need Scikit-learn requires: Python (>= 2.6 or >= 3.3), NumPy (>= 1.6.1), SciPy (>= 0.9).

simply type in terminal(assuming you have installed pip)

pip install -U numpy scipy scikit-learn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM