Skip to content

Instantly share code, notes, and snippets.

@thibthibaut
Created April 7, 2020 13:11
Show Gist options
  • Save thibthibaut/e96ef67d0816b9152840bdfd33ebdb5d to your computer and use it in GitHub Desktop.
Save thibthibaut/e96ef67d0816b9152840bdfd33ebdb5d to your computer and use it in GitHub Desktop.
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
data = dataset[:,0:8]
label = dataset[:,8]
X = Input(shape=(8,))
Y = Input(shape=(1,))
x = Dense(12, input_dim=8, activation='relu')(X)
x = Dense(8, activation='relu')(x)
predictions = Dense(1, activation='sigmoid')(x)
def custom_loss(l):
def loss(y_true, y_pred):
if l == 0:
return binary_crossentropy(y_true, y_pred)
else:
return mean_squared_error(y_true, y_pred)
return loss
# Compile model
model = Model(inputs=[X, Y], outputs=predictions)
model.compile(loss=custom_loss(Y), optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(x=[data, label], y=label, epochs=150)
# evaluate the model
scores = model.evaluate([data, label], label)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment