phanein/deepwalk

'numpy.ndarray' object has no attribute 'tocoo'

Anjs04 opened this issue · 4 comments

In scoring.py, on this line:
cy = y_train_.tocoo()

where y_train = [[] for x in range(y_train_.shape[0])]

GTmac commented

what is the format of your label matrix and what is the dataset you are using? You need to ensure that the label matrix is a sparse matrix in order to call .tocoo()

jml6m commented

I'm getting this same error but in training.py

Has something to do with my input set containing hot encodings (created using keras.utils.to_categorical) which required me to add InputLayer to the beginning of my sequential model as so:

model = keras.Sequential([
        keras.layers.InputLayer(input_shape=(55,), sparse=True),
        keras.layers.Dense(1024, activation=tf.nn.relu, kernel_initializer=init_orth, bias_initializer=init_0),
        keras.layers.Dense(512, activation=tf.nn.relu, kernel_initializer=init_orth, bias_initializer=init_0),
        keras.layers.Dense(256, activation=tf.nn.relu, kernel_initializer=init_orth, bias_initializer=init_0),
        keras.layers.Dense(128, activation=tf.nn.relu, kernel_initializer=init_orth, bias_initializer=init_0),
        keras.layers.Dense(32, activation=tf.nn.relu, kernel_initializer=init_orth, bias_initializer=init_0),
        keras.layers.Dense(1, activation=tf.nn.sigmoid)
    ])

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

GTmac commented

Do you also get the error on the same line? (cy = y_train_.tocoo()) If so -- what is the format of your input matrix? It must be a sparse matrix defined in scipy.sparse (such as https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html or https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html) otherwise the tocoo() method is not appliable.

jml6m commented

@GTmac I am trying to pass a matrix (numpy array essentially) to a keras model that contains values that are both numeric and categorical. From what I'm reading this may not be possible, yet someone in another thread suggested that using a sparse matrix may work. If you have any information that could help please let me know.

But you're right, I did not use a scipy.sparse matrix, therefore it's throwing the error. You can keep the issue closed.