Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Invalid arguments were passed to kmeans_cuda for metric="cos" #88

Open
mahfuzmohammad opened this issue Jul 12, 2019 · 2 comments

Comments

@mahfuzmohammad
Copy link

Hi,
I am trying to run the following example:

import numpy
from matplotlib import pyplot
from libKMCUDA import kmeans_cuda

numpy.random.seed(0)
arr = numpy.empty((10000, 2), dtype=numpy.float32)
angs = numpy.random.rand(10000) * 2 * numpy.pi
for i in range(10000):
arr[i] = numpy.sin(angs[i]), numpy.cos(angs[i])
centroids, assignments, avg_distance = kmeans_cuda(
arr, 4, metric="cos", verbosity=1, seed=3, average_distance=True)
print("Average distance between centroids and members:", avg_distance)
print(centroids)
pyplot.scatter(arr[:, 0], arr[:, 1], c=assignments)
pyplot.scatter(centroids[:, 0], centroids[:, 1], c="white", s=150)

But I am getting the error: ValueError: Invalid arguments were passed to kmeans_cuda

@randomrain101
Copy link

randomrain101 commented Aug 16, 2019

Apparently the cos metric only works for np.float16 dtype, not np.float32?
(notice: when using np.float16 the number of features has to be even, as discussed in #86 )

@davidlainesv
Copy link

In my case, I was able to use metric="cos" after doing

import numpy as np
from sklearn.preprocessing import normalize

X = normalize(data.values, norm='l2')

I suggest you to run the script in the terminal because jupyter hides part of the error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants