Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (e.g., 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.

like image 950
clwen Avatar asked Mar 05 '26 08:03

clwen


2 Answers

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).

like image 164
Fred Foo Avatar answered Mar 07 '26 22:03

Fred Foo


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

like image 37
aibotnet Avatar answered Mar 07 '26 23:03

aibotnet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!