What I'm trying to accomplish is having a set relationship between some custom input data and output data then have a neural network figure out this relationship/rule to predict future output given the input. I've set up some test code here where a random list of inputs is generated and if it is more than 0.5 the output is 1 otherwise the output is 0.
from tensorflow import keras
import numpy as np
# generate data
data_input_generate = np.random.random((6400, 1))
data_output_generate = np.random.randint(2, size=(6400, 1))
data_input = np.vstack([data_input_generate, data_input_generate])
data_output = np.vstack([data_output_generate, data_output_generate])
for i in range(len(data_input)):
if data_input[i] >= 0.5:
data_output[i] = [1]
else:
data_output[i] = [0]
# setup neural network
Inputs = keras.layers.Input(shape=(1, ))
hidden1 = keras.layers.Dense(units=100, activation="sigmoid")(Inputs)
hidden2 = keras.layers.Dense(units=100, activation='softmax')(hidden1)
predictions = keras.layers.Dense(units=1, activation='relu')(hidden2)
# initialize model
model = keras.Model([Inputs], outputs=predictions)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit
model.fit(data_input, data_output, batch_size=10, epochs=5)
# predict
predictions = model.predict(data_input_generate)
# print predictions
for i in range(10):
print(f"Value: {data_input_generate[i]}, Result: {data_output_generate[i]}, Prediction: {predictions[i]}")
The problem is, after fitting the model, the accuracy stays at 50%. Is this a problem with my layer activation function or the way I set up the model? My goal is to correctly predict the output with fairly high accuracy. Thanks in advance!