【发布时间】:2018-02-26 23:28:15
【问题描述】:
目前,我正在处理一个需要重新排序列表的 DP 项目,例如:
input_list = [1, 1, 2, 2]
output_list = [1, 2, 1, 2]
所以,我已经使用 Keras 的 to_categorical 函数对我的输入和输出列表进行了编码:
X = to_categorical(input_list, num_classes=10)
X
array([[ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.]])
在我将它们重塑为 3D 形状后(对于 LSTM):
X = X.reshape(1,4,10)
y = y.reshape(1,4,10)
对于损失函数和指标,我使用 binary_crossentropy 和 F1。
我的问题是准确性。有时我得到 f.e.列表中的数字错误:
y_out 是[1,2,2,2],但我需要[1,2,1,2]。
那么,我的问题:
- 对我的项目使用 to_categorical 编码数据是个好主意吗?
- 度量和损失函数呢?我应该尝试其他方法吗?
- 我真的很喜欢这种类型的错误 -> 我的 y_out 是
[1,2,2,2],但我需要[1,2,1,2]。 有什么办法克服它吗? - 另外,如果你知道类似的项目,请分享你的知识。
欢迎任何反馈:)
关于我的项目的一些额外数据:
代码:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
model = Sequential()
model.add(Bidirectional(GRU(32, return_sequences=True), input_shape=(None, 1)))
model.add(Dense(30, activation='elu'))
model.add(BatchNormalization())
model.add(Dense(1, activation='sigmoid', kernel_initializer='normal', use_bias=True))
model.compile(loss='binary_crossentropy', optimizer=keras.optimizers.Adam(lr=0.001),
metrics=[f1])
model.fit(a, y, epochs=5000, batch_size=500, callbacks = callbacks)
我的模型总结
Layer (type) Output Shape Param #
=================================================================
bidirectional_11 (Bidirectio (None, None, 64) 6528
_________________________________________________________________
dense_18 (Dense) (None, None, 30) 1950
_________________________________________________________________
batch_normalization_8 (Batch (None, None, 30) 120
_________________________________________________________________
dense_19 (Dense) (None, None, 1) 31
=================================================================
Total params: 8,629
Trainable params: 8,569
Non-trainable params: 60
【问题讨论】:
-
答案完全取决于“什么”是您的数据。
-
@DanielMöller 列表,正如我在开头所展示的那样。 F.e.我有输入列表
[1, 1, 1, 2, 2, 3]并希望在我的网络输出中获得类似[ 1, 1, 2, 3, 2, 1]的内容。
标签: python machine-learning deep-learning keras normalization