我是一个学习keras的新手,正在学习这个教程
手动生成的数据集:
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)
然后使用 MinMaxScaler 缩放样本
然后使用一个简单的顺序模型:
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
)
然而,准确率徘徊在 50% 左右,损失在 70% 左右。我尝试在我的 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
我只是按照教程进行操作,但无法理解我在哪里犯了错误。我是第一次学习keras。所以,请原谅。预先感谢。
手动生成的简单数据集上的简单序列模型。 准确率有望提高,但滞后 50% 左右。
我尝试通过向网络添加额外层来执行上述代码,并观察到模型精度有所提高。 请参考这个要点作为参考。