Up preprocessing_layer の作成 作成: 2021-04-23
更新: 2021-04-23


    numeric_columns と categorical_columns を結合し,これを tf.keras.layers.DenseFeatures に入力して,preprocessing_layer とする:
      >>> preprocessing_layer = \ ... tf.keras.layers.DenseFeatures( categorical_columns + numeric_columns )

    preprocessing_layer の機能チェック:
      >>> for batch in packed_train_data.take(1): ... print( preprocessing_layer(batch).numpy()[0] ) ... Traceback (most recent call last): File "<stdin>", line 2, in <module> File "/home/pi/venv/lib/python3.7/site-packages/ tensorflow_core/python/keras/engine/base_layer.py", line 913, in __call__outputs = self.call(cast_inputs, *args, **kwargs) File "/home/pi/venv/lib/python3.7/site-packages/ tensorflow_core/python/feature_column/dense_features.py", line 129, in call features) ValueError: ('We expected a dictionary here. Instead we got: ', (OrderedDict([ ('sex', <tf.Tensor: shape=(5,), dtype=string, numpy=array([b'male', b'female', b'male', b'female', b'male'], dtype=object)>), ('class', <tf.Tensor: shape=(5,), dtype=string, numpy=array([b'Third', b'First', b'Third', b'Second', b'First'], dtype=object)>), ('deck', <tf.Tensor: shape=(5,), dtype=string, numpy=array([b'unknown', b'E', b'unknown', b'unknown', b'B'], dtype=object)>), ('embark_town', <tf.Tensor: shape=(5,), dtype=string, numpy=array([b'Queenstown', b'Southampton', b'Southampton', b'Southampton', b'Southampton'], dtype=object)>), ('alone', <tf.Tensor: shape=(5,), dtype=string, numpy=array([b'y', b'n', b'y', b'y', b'n'], dtype=object)>), ('numeric', <tf.Tensor: shape=(5, 4), dtype=float32, numpy= array([[28. , 0. , 0. , 7.75], [33. , 1. , 0. , 53.1 ], [20. , 0. , 0. , 8.05], [35. , 0. , 0. , 21. ], [31. , 1. , 0. , 57. ]], dtype=float32)>) ]), <tf.Tensor: shape=(5,), dtype=int32, numpy=array([0, 1, 0, 1, 1])>)