1

I try to create a multi-label classificator using Keras. The training data has the following format:

X_train

f1  f2  f3
1   1   5
0   2   4
1   0   4

y_train:

c1  c2
0   1
1   1
0   0

This is the code that I use to build the model:

from keras.models import Sequential
from keras.layers import Dense
import math

def softmax(z):
    z_exp = [math.exp(i) for i in z]
    sum_z_exp = sum(z_exp)
    return [i / sum_z_exp for i in z_exp]

nn = Sequential()
nn.add(Dense(10, activation="relu", input_shape=(10,)))
nn.add(Dense(2, activation="sigmoid"))

nn.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

n = 10000
model.fit(X_train.values, y_train.values, batch_size=16, epochs=5, verbose=1, validation_split=0.1)

When I run this code, it fails with the message:

AttributeError: 'Sequential' object has no attribute '_feed_input_names'

1
  • A few hints, use activation='softmax' instead of using your custom softmax. That's because you are not using Keras symbolic tensors in that function. But since this code doesn't seem to use this activation, the problem is likely to be in X_train.values and Y_train.values. Make sure they both are numpy arrays with print(type(X_train.values)). Commented Sep 19, 2019 at 13:59

1 Answer 1

1

I' m writing my suggestions here because i can't comment yet. I think your input_shape might be off. You can find here and here that someone other had the same problem. Maybe try something like:

nn.add(Dense(.... input_dim=X_train.shape[1]))

I hope this helps :)

Sign up to request clarification or add additional context in comments.

Comments

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.