Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import keras
import numpy as np
model = keras.Sequential()
model.add(keras.layers.Dense(5, activation='sigmoid', input_shape=(1,)))
model.add(keras.layers.Dense(1, activation='sigmoid'))
model.compile('adadelta', 'mse', metrics=['accuracy'])
xs = np.array(range(1, 10))
ys = np.array([[0] for _ in range(5)] + [[1] for _ in range(4)])
model.fit(xs, ys, epochs=2000)
print(model.predict(xs))
# 9/9 [==============================] - 0s 82us/step - loss: 0.0155 - acc: 1.0000
# [[0.00141504]
# [0.00251564]
# [0.00749135]
# [0.0397768 ]
# [0.26316088]
# [0.74775267]
# [0.9371815 ]
# [0.9762724 ]
# [0.986349 ]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment