0

When I run

import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth
estimate_bandwidth(np.array([1,2,3,4,5,6]))

I get the error

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "[..]/anaconda2/envs/reifen/lib/python2.7/site-packages/sklearn/cluster/mean_shift_.py", line 72, in estimate_bandwidth
    d, _ = nbrs.kneighbors(X[batch, :], return_distance=True)
IndexError: too many indices for array

I understand that the dimensionality of the array is not correct - but I am not sure what I did wrong here - the code isn't that long. Can estimate_bandwidth only be used with data that is multivariate?

2
  • You should read the documentation - scikit-learn.org/stable/modules/generated/… Commented May 12, 2017 at 10:03
  • 1
    @Craicerjack: I did, but didn't read anything about this. However reading again, I gathered that for the univariate case I need to use .reshape((6, 1)) after the array. Thanks. Commented May 12, 2017 at 10:08

1 Answer 1

1

Ypu should do something like this:

import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth

array = np.array([1,2,3,4,5,6])

d = estimate_bandwidth(array.reshape(len(array),1))
Sign up to request clarification or add additional context in comments.

2 Comments

Although this is exactly what I just commented ;-) - it is the correct solution.
Yeah. probably :-). Happens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.