1

I am writing this code and keep getting the Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead. error no matter what I try. Do you see the problem within my code?

df = pd.read_csv('drain.csv')
values = df.values
seed = 7
numpy.random.seed(seed)
X = df.iloc[:,:2]
Y = df.iloc[:,2:]
def create_model():
# create model
    model = Sequential()
    model.add(Dense(12, input_dim=8, activation='relu'))
    model.add(Dense(8, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model
model = KerasClassifier(build_fn=create_model, epochs=10, batch_size=10, verbose=0)
# evaluate using 10-fold cross validation
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
results = cross_val_score(model, X, Y, cv=kfold)
print(results.mean())
Sarath Chandra Vema
  • 792
  • 1
  • 6
  • 13
  • please paste the error. You are missing something over here. Final output should be a binary, instead you are receiving a continuous output. – Sarath Chandra Vema Oct 28 '19 at 03:17
  • You are giving wrong output target. You are trying to classify your data and classification target should be one hot vector so check your elements stored in Y. It should be a vector rather than matrix in your case . And its elements should be zero or one. – overfit Oct 28 '19 at 03:22

1 Answers1

2

You need to convert your Y variables to binary, as specified here : https://github.com/keras-team/keras/blob/master/examples/mnist_mlp.py

# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

and then

history = model.fit(x_train, y_train,
                    batch_size=batch_size,
                    epochs=epochs,
                    verbose=1,
                    validation_data=(x_test, y_test))

Seems like you forgot the conversion to categorical step.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Sarath Chandra Vema
  • 792
  • 1
  • 6
  • 13