为什么 AUC 不同?以及如何将 model.predict 转换为 AUC = 0.9013 的标签
model = keras.Sequential([
keras.layers.Dense(4096, activation='relu'),
keras.layers.Reshape((16,256)),
keras.layers.Conv1D(64,2),
keras.layers.Flatten(),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(1)
])
model.compile(optimizer='RMSprop',
loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
metrics=tf.keras.metrics.AUC(from_logits=True))
model.fit(X, Y, epochs=20, batch_size=64, validation_split=0.15)
Epoch 20/20
129/129 [==============================] - 3s 21ms/step - loss: 0.2583 - auc_1: 0.9585 - val_loss: 0.4556 - val_auc_1: 0.9075
model.evaluate(Xt,Yt,batch_size=64)
75/75 [==============================] - 0s 6ms/step - loss: 0.4977 - auc_1: 0.9013
[0.4976920783519745, 0.9013347029685974]
pred = model.predict(Xt, batch_size=32, verbose=1)
print(pred)
149/149 [==============================] - 1s 8ms/step
[[-13.761446 ]
[ 1.0361784]
[ 0.439698 ]
...
[ 9.102252 ]
[ 2.4544861]
[ 0.8873279]]
m = tf.keras.metrics.AUC(from_logits=True)
m.update_state(y_test, pred)
m.result()
<tf.Tensor: shape=(), dtype=float32, numpy=0.9013347>
b = tf.keras.activations.sigmoid(pred)
b.numpy()
x = []
for xser in b.numpy():
if xser > 0.5:
print (xser, ' 1')
x.append(1)
else:
print (xser, ' 0')
x.append(0)
k = tf.keras.metrics.AUC(from_logits=False)
k.update_state(y_test, x)
k.result()
<tf.Tensor: shape=(), dtype=float32, numpy=0.81831676>
为什么 AUC 不同?以及如何将 model.predict 转换为 AUC = 0.9013 的标签