In [1]:
# Create your first MLP in Keras
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
numpy.random.seed(7)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:, 0:8]
Y = dataset[:, 8]
# 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'])
# Fit the model
model.fit(X, Y, epochs=150, batch_size=10)
# evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
Using TensorFlow backend.
WARNING:tensorflow:From D:\ProgramData\Anaconda3\envs\deep\lib\site-packages\tensorflow\python\ops\nn_impl.py:180: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
WARNING:tensorflow:From D:\ProgramData\Anaconda3\envs\deep\lib\site-packages\keras\backend\tensorflow_backend.py:422: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

Epoch 1/150
768/768 [==============================] - 2s 3ms/step - loss: 3.1948 - accuracy: 0.5833
Epoch 2/150
768/768 [==============================] - 0s 103us/step - loss: 0.9527 - accuracy: 0.5781
Epoch 3/150
768/768 [==============================] - 0s 106us/step - loss: 0.7632 - accuracy: 0.6302
Epoch 4/150
768/768 [==============================] - 0s 101us/step - loss: 0.7209 - accuracy: 0.6510
Epoch 5/150
768/768 [==============================] - 0s 104us/step - loss: 0.6933 - accuracy: 0.6693
Epoch 6/150
768/768 [==============================] - 0s 105us/step - loss: 0.6687 - accuracy: 0.6875
Epoch 7/150
768/768 [==============================] - 0s 105us/step - loss: 0.6621 - accuracy: 0.6758
Epoch 8/150
768/768 [==============================] - 0s 108us/step - loss: 0.6493 - accuracy: 0.6862
Epoch 9/150
768/768 [==============================] - 0s 106us/step - loss: 0.6340 - accuracy: 0.6953
Epoch 10/150
768/768 [==============================] - 0s 105us/step - loss: 0.6417 - accuracy: 0.6797
Epoch 11/150
768/768 [==============================] - 0s 104us/step - loss: 0.6576 - accuracy: 0.6667
Epoch 12/150
768/768 [==============================] - 0s 108us/step - loss: 0.6506 - accuracy: 0.6810
Epoch 13/150
768/768 [==============================] - 0s 106us/step - loss: 0.6332 - accuracy: 0.6758
Epoch 14/150
768/768 [==============================] - 0s 114us/step - loss: 0.6211 - accuracy: 0.7044
Epoch 15/150
768/768 [==============================] - 0s 123us/step - loss: 0.6020 - accuracy: 0.7070
Epoch 16/150
768/768 [==============================] - 0s 126us/step - loss: 0.5876 - accuracy: 0.7070
Epoch 17/150
768/768 [==============================] - 0s 113us/step - loss: 0.5824 - accuracy: 0.7070
Epoch 18/150
768/768 [==============================] - 0s 114us/step - loss: 0.5942 - accuracy: 0.6966
Epoch 19/150
768/768 [==============================] - 0s 112us/step - loss: 0.5741 - accuracy: 0.7044
Epoch 20/150
768/768 [==============================] - 0s 117us/step - loss: 0.5731 - accuracy: 0.7292
Epoch 21/150
768/768 [==============================] - 0s 113us/step - loss: 0.5654 - accuracy: 0.7174
Epoch 22/150
768/768 [==============================] - 0s 113us/step - loss: 0.5778 - accuracy: 0.7044
Epoch 23/150
768/768 [==============================] - 0s 113us/step - loss: 0.5716 - accuracy: 0.7135
Epoch 24/150
768/768 [==============================] - 0s 119us/step - loss: 0.5690 - accuracy: 0.7318
Epoch 25/150
768/768 [==============================] - 0s 119us/step - loss: 0.5554 - accuracy: 0.7448
Epoch 26/150
768/768 [==============================] - 0s 123us/step - loss: 0.5725 - accuracy: 0.7031
Epoch 27/150
768/768 [==============================] - 0s 104us/step - loss: 0.5552 - accuracy: 0.7253
Epoch 28/150
768/768 [==============================] - 0s 104us/step - loss: 0.5586 - accuracy: 0.7214
Epoch 29/150
768/768 [==============================] - 0s 117us/step - loss: 0.5773 - accuracy: 0.7174
Epoch 30/150
768/768 [==============================] - 0s 117us/step - loss: 0.5614 - accuracy: 0.7188
Epoch 31/150
768/768 [==============================] - 0s 109us/step - loss: 0.5713 - accuracy: 0.7109
Epoch 32/150
768/768 [==============================] - 0s 109us/step - loss: 0.5654 - accuracy: 0.7161
Epoch 33/150
768/768 [==============================] - 0s 105us/step - loss: 0.5505 - accuracy: 0.7214
Epoch 34/150
768/768 [==============================] - 0s 109us/step - loss: 0.5535 - accuracy: 0.7357
Epoch 35/150
768/768 [==============================] - 0s 104us/step - loss: 0.5541 - accuracy: 0.7240
Epoch 36/150
768/768 [==============================] - 0s 104us/step - loss: 0.5630 - accuracy: 0.7148
Epoch 37/150
768/768 [==============================] - 0s 104us/step - loss: 0.5320 - accuracy: 0.7331
Epoch 38/150
768/768 [==============================] - ETA: 0s - loss: 0.4983 - accuracy: 0.74 - 0s 105us/step - loss: 0.5406 - accuracy: 0.7266
Epoch 39/150
768/768 [==============================] - 0s 105us/step - loss: 0.5502 - accuracy: 0.7240
Epoch 40/150
768/768 [==============================] - 0s 109us/step - loss: 0.5465 - accuracy: 0.7253
Epoch 41/150
768/768 [==============================] - 0s 108us/step - loss: 0.5448 - accuracy: 0.7227
Epoch 42/150
768/768 [==============================] - 0s 103us/step - loss: 0.5392 - accuracy: 0.7318
Epoch 43/150
768/768 [==============================] - 0s 108us/step - loss: 0.5328 - accuracy: 0.7383
Epoch 44/150
768/768 [==============================] - 0s 105us/step - loss: 0.5360 - accuracy: 0.7474
Epoch 45/150
768/768 [==============================] - 0s 105us/step - loss: 0.5344 - accuracy: 0.7591
Epoch 46/150
768/768 [==============================] - 0s 108us/step - loss: 0.5268 - accuracy: 0.7487
Epoch 47/150
768/768 [==============================] - 0s 109us/step - loss: 0.5366 - accuracy: 0.7344
Epoch 48/150
768/768 [==============================] - 0s 107us/step - loss: 0.5349 - accuracy: 0.7409
Epoch 49/150
768/768 [==============================] - 0s 107us/step - loss: 0.5366 - accuracy: 0.7539
Epoch 50/150
768/768 [==============================] - 0s 105us/step - loss: 0.5289 - accuracy: 0.7383
Epoch 51/150
768/768 [==============================] - 0s 109us/step - loss: 0.5316 - accuracy: 0.7500
Epoch 52/150
768/768 [==============================] - 0s 103us/step - loss: 0.5419 - accuracy: 0.7305
Epoch 53/150
768/768 [==============================] - 0s 110us/step - loss: 0.5372 - accuracy: 0.7461
Epoch 54/150
768/768 [==============================] - 0s 110us/step - loss: 0.5435 - accuracy: 0.7331
Epoch 55/150
768/768 [==============================] - 0s 109us/step - loss: 0.5207 - accuracy: 0.7422
Epoch 56/150
768/768 [==============================] - 0s 114us/step - loss: 0.5302 - accuracy: 0.7422
Epoch 57/150
768/768 [==============================] - 0s 100us/step - loss: 0.5369 - accuracy: 0.7474
Epoch 58/150
768/768 [==============================] - 0s 103us/step - loss: 0.5268 - accuracy: 0.7461
Epoch 59/150
768/768 [==============================] - 0s 101us/step - loss: 0.5132 - accuracy: 0.7552
Epoch 60/150
768/768 [==============================] - 0s 101us/step - loss: 0.5350 - accuracy: 0.7331
Epoch 61/150
768/768 [==============================] - 0s 100us/step - loss: 0.5304 - accuracy: 0.7253
Epoch 62/150
768/768 [==============================] - 0s 110us/step - loss: 0.5224 - accuracy: 0.7409
Epoch 63/150
768/768 [==============================] - 0s 108us/step - loss: 0.5472 - accuracy: 0.7253
Epoch 64/150
768/768 [==============================] - 0s 104us/step - loss: 0.5369 - accuracy: 0.7331
Epoch 65/150
768/768 [==============================] - 0s 108us/step - loss: 0.5257 - accuracy: 0.7396
Epoch 66/150
768/768 [==============================] - 0s 99us/step - loss: 0.5090 - accuracy: 0.7422
Epoch 67/150
768/768 [==============================] - 0s 99us/step - loss: 0.5180 - accuracy: 0.7435
Epoch 68/150
768/768 [==============================] - 0s 104us/step - loss: 0.5192 - accuracy: 0.7500
Epoch 69/150
768/768 [==============================] - 0s 108us/step - loss: 0.5209 - accuracy: 0.7266
Epoch 70/150
768/768 [==============================] - 0s 97us/step - loss: 0.5339 - accuracy: 0.7227
Epoch 71/150
768/768 [==============================] - 0s 101us/step - loss: 0.5228 - accuracy: 0.7409
Epoch 72/150
768/768 [==============================] - 0s 99us/step - loss: 0.5179 - accuracy: 0.7500
Epoch 73/150
768/768 [==============================] - 0s 97us/step - loss: 0.5175 - accuracy: 0.7448
Epoch 74/150
768/768 [==============================] - 0s 96us/step - loss: 0.5156 - accuracy: 0.7461
Epoch 75/150
768/768 [==============================] - 0s 92us/step - loss: 0.5142 - accuracy: 0.7435
Epoch 76/150
768/768 [==============================] - 0s 97us/step - loss: 0.5127 - accuracy: 0.7539
Epoch 77/150
768/768 [==============================] - 0s 106us/step - loss: 0.5236 - accuracy: 0.7487
Epoch 78/150
768/768 [==============================] - 0s 104us/step - loss: 0.5173 - accuracy: 0.7500
Epoch 79/150
768/768 [==============================] - 0s 106us/step - loss: 0.5122 - accuracy: 0.7513
Epoch 80/150
768/768 [==============================] - 0s 110us/step - loss: 0.5138 - accuracy: 0.7578
Epoch 81/150
768/768 [==============================] - 0s 104us/step - loss: 0.5106 - accuracy: 0.7474
Epoch 82/150
768/768 [==============================] - 0s 113us/step - loss: 0.4992 - accuracy: 0.7513
Epoch 83/150
768/768 [==============================] - 0s 109us/step - loss: 0.5000 - accuracy: 0.7539
Epoch 84/150
768/768 [==============================] - 0s 106us/step - loss: 0.4943 - accuracy: 0.7578
Epoch 85/150
768/768 [==============================] - 0s 109us/step - loss: 0.5056 - accuracy: 0.7422
Epoch 86/150
768/768 [==============================] - 0s 108us/step - loss: 0.5067 - accuracy: 0.7435
Epoch 87/150
768/768 [==============================] - 0s 109us/step - loss: 0.4967 - accuracy: 0.7526
Epoch 88/150
768/768 [==============================] - 0s 114us/step - loss: 0.4976 - accuracy: 0.7604
Epoch 89/150
768/768 [==============================] - 0s 113us/step - loss: 0.5038 - accuracy: 0.7721
Epoch 90/150
768/768 [==============================] - 0s 109us/step - loss: 0.5066 - accuracy: 0.7500
Epoch 91/150
768/768 [==============================] - 0s 116us/step - loss: 0.4990 - accuracy: 0.7474
Epoch 92/150
768/768 [==============================] - 0s 114us/step - loss: 0.5046 - accuracy: 0.7487
Epoch 93/150
768/768 [==============================] - 0s 113us/step - loss: 0.4940 - accuracy: 0.7552
Epoch 94/150
768/768 [==============================] - 0s 113us/step - loss: 0.4933 - accuracy: 0.7656
Epoch 95/150
768/768 [==============================] - 0s 113us/step - loss: 0.5047 - accuracy: 0.7396
Epoch 96/150
768/768 [==============================] - 0s 117us/step - loss: 0.4861 - accuracy: 0.7708
Epoch 97/150
768/768 [==============================] - 0s 105us/step - loss: 0.4905 - accuracy: 0.7773
Epoch 98/150
768/768 [==============================] - 0s 106us/step - loss: 0.4866 - accuracy: 0.7539
Epoch 99/150
768/768 [==============================] - 0s 104us/step - loss: 0.4880 - accuracy: 0.7695
Epoch 100/150
768/768 [==============================] - 0s 109us/step - loss: 0.4868 - accuracy: 0.7604
Epoch 101/150
768/768 [==============================] - 0s 119us/step - loss: 0.4856 - accuracy: 0.7786
Epoch 102/150
768/768 [==============================] - 0s 110us/step - loss: 0.5008 - accuracy: 0.7513
Epoch 103/150
768/768 [==============================] - 0s 108us/step - loss: 0.4964 - accuracy: 0.7578
Epoch 104/150
768/768 [==============================] - 0s 109us/step - loss: 0.4892 - accuracy: 0.7904
Epoch 105/150
768/768 [==============================] - 0s 116us/step - loss: 0.5213 - accuracy: 0.7383
Epoch 106/150
768/768 [==============================] - 0s 114us/step - loss: 0.4911 - accuracy: 0.7773
Epoch 107/150
768/768 [==============================] - 0s 112us/step - loss: 0.4899 - accuracy: 0.7721
Epoch 108/150
768/768 [==============================] - 0s 112us/step - loss: 0.5021 - accuracy: 0.7617
Epoch 109/150
768/768 [==============================] - 0s 110us/step - loss: 0.4821 - accuracy: 0.7604
Epoch 110/150
768/768 [==============================] - 0s 116us/step - loss: 0.4865 - accuracy: 0.7630
Epoch 111/150
768/768 [==============================] - 0s 110us/step - loss: 0.4814 - accuracy: 0.7734
Epoch 112/150
768/768 [==============================] - 0s 110us/step - loss: 0.4934 - accuracy: 0.7643
Epoch 113/150
768/768 [==============================] - 0s 113us/step - loss: 0.4977 - accuracy: 0.7526
Epoch 114/150
768/768 [==============================] - 0s 113us/step - loss: 0.4890 - accuracy: 0.7500
Epoch 115/150
768/768 [==============================] - 0s 109us/step - loss: 0.4874 - accuracy: 0.7682
Epoch 116/150
768/768 [==============================] - 0s 109us/step - loss: 0.4909 - accuracy: 0.7669
Epoch 117/150
768/768 [==============================] - 0s 110us/step - loss: 0.4915 - accuracy: 0.7617
Epoch 118/150
768/768 [==============================] - 0s 114us/step - loss: 0.4876 - accuracy: 0.7826
Epoch 119/150
768/768 [==============================] - 0s 112us/step - loss: 0.4865 - accuracy: 0.7669
Epoch 120/150
768/768 [==============================] - 0s 109us/step - loss: 0.4972 - accuracy: 0.7630
Epoch 121/150
768/768 [==============================] - 0s 110us/step - loss: 0.4951 - accuracy: 0.7617
Epoch 122/150
768/768 [==============================] - 0s 108us/step - loss: 0.4811 - accuracy: 0.7656
Epoch 123/150
768/768 [==============================] - 0s 110us/step - loss: 0.4864 - accuracy: 0.7643
Epoch 124/150
768/768 [==============================] - 0s 114us/step - loss: 0.4819 - accuracy: 0.7682
Epoch 125/150
768/768 [==============================] - 0s 118us/step - loss: 0.4816 - accuracy: 0.7917
Epoch 126/150
768/768 [==============================] - 0s 112us/step - loss: 0.4781 - accuracy: 0.7643
Epoch 127/150
768/768 [==============================] - 0s 112us/step - loss: 0.4882 - accuracy: 0.7591
Epoch 128/150
768/768 [==============================] - 0s 114us/step - loss: 0.4688 - accuracy: 0.7604
Epoch 129/150
768/768 [==============================] - 0s 113us/step - loss: 0.4810 - accuracy: 0.7669
Epoch 130/150
768/768 [==============================] - 0s 117us/step - loss: 0.4669 - accuracy: 0.7852
Epoch 131/150
768/768 [==============================] - 0s 113us/step - loss: 0.4735 - accuracy: 0.7695
Epoch 132/150
768/768 [==============================] - 0s 113us/step - loss: 0.4766 - accuracy: 0.7721
Epoch 133/150
768/768 [==============================] - 0s 112us/step - loss: 0.4793 - accuracy: 0.7630
Epoch 134/150
768/768 [==============================] - 0s 114us/step - loss: 0.4809 - accuracy: 0.7643
Epoch 135/150
768/768 [==============================] - 0s 118us/step - loss: 0.4713 - accuracy: 0.7682
Epoch 136/150
768/768 [==============================] - 0s 112us/step - loss: 0.4685 - accuracy: 0.7721
Epoch 137/150
768/768 [==============================] - 0s 114us/step - loss: 0.4652 - accuracy: 0.7826
Epoch 138/150
768/768 [==============================] - 0s 119us/step - loss: 0.4755 - accuracy: 0.7773
Epoch 139/150
768/768 [==============================] - 0s 120us/step - loss: 0.4661 - accuracy: 0.7773
Epoch 140/150
768/768 [==============================] - 0s 113us/step - loss: 0.4763 - accuracy: 0.7839
Epoch 141/150
768/768 [==============================] - 0s 110us/step - loss: 0.4713 - accuracy: 0.7747
Epoch 142/150
768/768 [==============================] - 0s 110us/step - loss: 0.4815 - accuracy: 0.7591
Epoch 143/150
768/768 [==============================] - 0s 105us/step - loss: 0.4739 - accuracy: 0.7708
Epoch 144/150
768/768 [==============================] - 0s 106us/step - loss: 0.4714 - accuracy: 0.7760
Epoch 145/150
768/768 [==============================] - 0s 112us/step - loss: 0.4840 - accuracy: 0.7747
Epoch 146/150
768/768 [==============================] - 0s 116us/step - loss: 0.4945 - accuracy: 0.7565
Epoch 147/150
768/768 [==============================] - 0s 114us/step - loss: 0.4835 - accuracy: 0.7695
Epoch 148/150
768/768 [==============================] - 0s 109us/step - loss: 0.4721 - accuracy: 0.7760
Epoch 149/150
768/768 [==============================] - 0s 116us/step - loss: 0.4692 - accuracy: 0.7760
Epoch 150/150
768/768 [==============================] - 0s 110us/step - loss: 0.4758 - accuracy: 0.7760
768/768 [==============================] - 0s 56us/step

accuracy: 77.21%