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

coclust.clustering.SphericalKmeans returns AttributeError: 'numpy.ndarray' object has no attribute 'todense' #17

Open
ahgraber opened this issue Nov 1, 2019 · 1 comment

Comments

@ahgraber
Copy link

ahgraber commented Nov 1, 2019

I have a 2D numpy array 'doc_vecs' of document vectors (axis 0 is a document; axis 1 is the vector representation). When I try to pass this to SphericalKmeans I get the following error:


AttributeError Traceback (most recent call last)
.py in
7 start = timeit.default_timer()
8 skm_model = SphericalKmeans(n_clusters=k, weighting=False)
----> 9 skm_model.fit(doc_vecs)
10 skm_labels.append(skm_model.labels_)
11 skm_criterion.append(skm_model.criterion)

~/miniconda3/envs/nlp_tm/lib/python3.7/site-packages/coclust/clustering/spherical_kmeans.py in fit(self, X, y)
92 X = transformer.fit_transform(X)
93
---> 94 X = X.todense()
95 X = np.array(X)
96 X = sp.lil_matrix(X)

AttributeError: 'numpy.ndarray' object has no attribute 'todense'

Relevant versioning info:
MacOS 10.14.6
Anaconda Python 3.7.3
numpy = 1.16.4
scipy = 1.3.1
scikit-learn = 0.21.2
matplotlib = 3.1.1
coclust = 0.2.1

Thanks for your help!

@smorbieu
Copy link
Collaborator

smorbieu commented Nov 2, 2019

Thank you for the bug report.

As a workaround until we fix it, you can transform the array into a sparse matrix :

from scipy.sparse.csc import csc_matrix

doc_vecs = csc_matrix(doc_vecs)

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

2 participants