I am a newbie learning keras following this tutorial
Manually Generated Dataset:
- An experiential drug was test on individuals from ages 13 to 100 in a clinical trial
- The trial had 2100 participants. Half were under 65 years old & rest above 65 years or older.
- Around 95% of the patients 65 or older experienced side effects.
- Around 95% of patients under 65 experienced no side effects.
for i in range (50):
# The ~5% of younger patients who did experience side effects
random_younger = randint(13,64)
train_samples.append(random_younger)
train_labels.append(1)
# The ~5% of older patients who did not experience side effects
random_older = randint(65,100)
train_samples.append(random_older)
train_labels.append(0)
for i in range(1000):
# The ~95% of younger patients who did not experience side effects
random_younger = randint(13,64)
train_samples.append(random_younger)
train_labels.append(0)
# The ~95% of older patients who did experience side effects
random_older = randint(65,100)
train_samples.append(random_older)
train_labels.append(1)
Then the samples are scaled using MinMaxScaler
Then used a simple Sequential Model:
model = Sequential([
Dense(units=16, input_shape=(1,), activation='relu'),
Dense(units=32, activation='relu'),
Dense(units=2, activation='softmax')
])
model.compile(
optimizer=Adam(learning_rate=0.005),
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
model.fit(
x=scaled_train_samples,
y=train_labels,
batch_size=10,
epochs=30,
shuffle=True,
verbose=2
)
However, the accuracy lingers around 50% and loss is around 70%. I tried executing on both my PC & Google colab.
Epoch 1/30
210/210 - 2s - loss: 0.7457 - accuracy: 0.5029 - 2s/epoch - 7ms/step
Epoch 2/30
210/210 - 0s - loss: 0.7254 - accuracy: 0.4957 - 413ms/epoch - 2ms/step
Epoch 3/30
210/210 - 0s - loss: 0.7142 - accuracy: 0.5048 - 353ms/epoch - 2ms/step
Epoch 4/30
210/210 - 0s - loss: 0.6964 - accuracy: 0.4914 - 386ms/epoch - 2ms/step
Epoch 5/30
210/210 - 0s - loss: 0.6971 - accuracy: 0.5090 - 371ms/epoch - 2ms/step
Epoch 6/30
210/210 - 0s - loss: 0.6969 - accuracy: 0.4938 - 351ms/epoch - 2ms/step
Epoch 7/30
210/210 - 0s - loss: 0.6958 - accuracy: 0.4929 - 385ms/epoch - 2ms/step
...
...
Epoch 24/30
210/210 - 0s - loss: 0.6936 - accuracy: 0.5000 - 367ms/epoch - 2ms/step
Epoch 25/30
210/210 - 0s - loss: 0.6935 - accuracy: 0.5010 - 367ms/epoch - 2ms/step
Epoch 26/30
210/210 - 0s - loss: 0.6940 - accuracy: 0.4962 - 354ms/epoch - 2ms/step
Epoch 27/30
210/210 - 0s - loss: 0.6936 - accuracy: 0.4819 - 472ms/epoch - 2ms/step
Epoch 28/30
210/210 - 0s - loss: 0.6937 - accuracy: 0.4943 - 388ms/epoch - 2ms/step
Epoch 29/30
210/210 - 0s - loss: 0.6938 - accuracy: 0.4905 - 406ms/epoch - 2ms/step
Epoch 30/30
210/210 - 0s - loss: 0.6935 - accuracy: 0.4990 - 389ms/epoch - 2ms/step
I just followed as per the tutorial, but couldn’t understand where I’ve commited the mistake. I am learning keras for the first time. So, kindly pardon. Thanks in advance.
A simple Sequential model on a manually generated simple dataset.
The accuracy is expected to improve, but lags around 50%.
Shivaja Kamalanayani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.