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'
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 inX_train.valuesandY_train.values. Make sure they both are numpy arrays withprint(type(X_train.values)).