sknetwork-team / scikit-network

Graph Algorithms
Other
602 stars 67 forks source link

KMeans does not work with numpy.ndarray #548

Closed sgerbe closed 1 year ago

sgerbe commented 1 year ago

Description

Trying to use sknetwork.clustering.KMeans() with an numpy.ndarray gives me a ValueError: Different number of diagonals and offsets.

What I Did

kmeans = KMeans(n_clusters=nclust)
labels = kmeans.fit_transform(adjacency) # adjacency is type numpy.ndarray

This fixes the problem:

adjacency = sparse.csr_matrix(adjacency)
kmeans = KMeans(n_clusters=nclust)
labels = kmeans.fit_transform(adjacency) # adjacency is type numpy.ndarray

I am guessing KMeans.fit() does not assign the check_format back to the input matrix:

Is (Line 113):

self._init_vars()

# input
check_format(input_matrix)

Maybe should be:

self._init_vars()

# input
input_matrix = check_format(input_matrix)
tbonald commented 1 year ago

Thanks for the notice! This has be fixed on the Develop branch.