對于既有數值特征,又有類别特征的輸入情況,使用 keras的預處理層進行轉換。
https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/structured_data/preprocessing_layers.ipynb?hl=ar-bh#scrollTo=sMYQvJuBi7MS
This tutorial demonstrates how to classify structured data (e.g. tabular data in a CSV). You will use Keras to define the model, and preprocessing layers as a bridge to map from columns in a CSV to features used to train the model. This tutorial contains complete code to: Load a CSV file using Pandas. Build an input pipeline to batch and shuffle the rows using tf.data. Map from columns in the CSV to features used to train the model using Keras Preprocessing layers. Build, train, and evaluate a model using Keras. Note: This tutorial is similar to Classify structured data with feature columns. This version uses new experimental Keras Preprocessing Layers instead of <code>tf.feature_column</code>. Keras Preprocessing Layers are more intuitive, and can be easily included inside your model to simplify deployment.
數值型 , 定義輸入, 進行正規化變換。
類别性, 轉換為整數, 對整數進行類别編碼, one-hot-code

https://www.tensorflow.org/api_docs/python/tf/keras/layers/experimental/preprocessing/CategoryEncoding
This layer provides options for condensing data into a categorical encoding. It accepts integer values as inputs and outputs a dense representation (one sample = 1-index tensor of float values representing data about the sample's tokens) of those inputs.
index -- 字元查詢表, 根據字元,查到index
encoder-- 根據index查詢到的index,生成one-hot碼
測試輸出
生成一個正則轉換器。
例子,将對應特征,做正規化處理。
all_input 存儲 所有的輸入層單元
encoded_features 存儲 所有的輸入層單元, 經過預處理管線後的 邏輯單元, 例如 正規化對象, 和 ONE-HOT 編碼對象。
使用 concatenate 接口,将所有的 編碼特征, 連接配接起來。
構成統一的特征向量輸出。
然後,将統一的特征向量輸出, 連接配接到 第一層稠密層單元, 然後連接配接到第二層稠密層單元。
第二層稠密層單元,就是作為模型輸出。
tf.keras.Model 模型的一個參數,是對所有輸入輸出的 規約;
第二個參數,是經過一些列預處理和模型本身的管線輸出, 模型輸出的規約。
https://www.tensorflow.org/api_docs/python/tf/keras/layers/concatenate
https://www.tensorflow.org/guide/tensor
A rank-4 tensor, shape: <code>[3, 2, 4, 5]</code>
出處:http://www.cnblogs.com/lightsong/
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接。