sklean fit_predict not accepting a 2 dimensional numpy array
<p>I am trying to perform some clustering analysis using three different clustering algorithms. I am loading in data from stdin as follows</p>

<pre><code>import sklearn.cluster as cluster

X = []
for line in sys.stdin:
    x1, x2 = line.strip().split()
    X.append([float(x1), float(x2)])
X = numpy.array(X)
</code></pre>

<p>and then storing my clustering parameters and types in an array as such</p>

<pre><code>clustering_configs = [
    ### K-Means
    ['KMeans', {'n_clusters' : 5}],
    ### Ward
    ['AgglomerativeClustering', {
                'n_clusters' : 5,
                'linkage' : 'ward'
                }],
    ### DBSCAN
    ['DBSCAN', {'eps' : 0.15}]
]
</code></pre>

<p>And I am trying to call them in a for loop</p>

<pre><code>for alg_name, alg_params in clustering_configs:

    class_ = getattr(cluster, alg_name)
    instance_ = class_(alg_params)

    instance_.fit_predict(X)
</code></pre>

<p>Everything is working correctly except for the <code>instance_.fit_prefict(X)</code> function. I am getting returned an error </p>

<pre><code>Traceback (most recent call last):
  File "meta_cluster.py", line 47, in &lt;module&gt;
    instance_.fit_predict(X)
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/k_means_.py", line 830, in fit_predict
    return self.fit(X).labels_
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/k_means_.py", line 812, in fit
    X = self._check_fit_data(X)
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.17.1-py2.7-linux-x86_64.egg/sklearn/cluster/k_means_.py", line 789, in _check_fit_data
    X.shape[0], self.n_clusters))
TypeError: %d format: a number is required, not dict
</code></pre>

<p>Anyone have a clue where I could be going wrong? I read the sklearn docs <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html#sklearn.cluster.KMeans.fit_predict" rel="nofollow">here</a> and it claims you just need an <code>array-like or sparse matrix, shape=(n_samples, n_features)</code> which I believe I have.</p>

<p>Any suggestions? Thanks!</p>

<pre><code> class sklearn.cluster.KMeans(n_clusters=8, init='k-means++', n_init=10, max_iter=300, tol=0.0001, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1, algorithm='auto')[source]
</code></pre>

<p>They way you'd call the KMeans class is,</p>

<pre><code>KMeans(n_clusters=5)
</code></pre>

<p>With your current code you are calling</p>

<pre><code>KMeans({'n_clusters': 5})
</code></pre>

<p>which is causing alg_params to be passed as a Dict instead of a class parameter. Same goes for the other algorithms.</p>

python numpy scikit-learn