我也感觉顺序不太对。 例子:
for x, y in train_dataset.take(1):
print(x))
print(keras.layers.DenseFeatures(feature_columns)(x).numpy())
输出: x的顺序第一个是sex : 详细为: x:{'sex': <....([b'male', b'female', b'female', b'female', b'female'], >, 'age': <...array([25., 28., 49., 35., 41.])>, 'n_siblings_spouses': <...array([0, 0, 0, 1, 0], )>, 'parch': <...array([0, 0, 0, 1, 2],)>, 'fare': <....array([ 7.7417, 12.35 , 25.9292, 20.25 , 20.2125])>, 'class': <.....>, 'deck': <....>, 'embark_town': <....>, 'alone': <..array([b'y', b'y', b'y', b'n', b'n'],)>}
而DenseFeature后的第一个值不是sex的one-hot编码而为25 ,具体整个的输出为 :
total:
[[25. 0. 1. 1. 0. 0. 1. 0. 0.
0. 0. 0. 0. 0. 0. 0. 1. 0.
7.7417 0. 1. 0. 0. 0. 0. 0. 1.
0. 0. 0. 0. 0. 1. 0. ]
[28. 0. 1. 0. 0. 1. 0. 0. 0.
0. 0. 0. 0. 1. 0. 0. 1. 0.
12.35 0. 1. 0. 0. 0. 0. 0. 1.
0. 0. 0. 0. 0. 0. 1. ]
]