A Keras preprocessing layer transforms tabular features inside a Keras model, reducing the need for separate custom preprocessing pipelines. Continuous inputs can be normalized, while categorical inputs can be looked up and encoded before reaching the model. section 9.3 section 9.3.2
A practical tabular workflow uses preprocessing layers to:
- Convert DataFrame rows into batched tf.data.Dataset objects, optionally shuffling training data and prefetching batches. section 9.3.2
- Adapt a Normalization layer to each continuous feature using training data. section 9.3.2
- Adapt StringLookup or IntegerLookup and apply CategoryEncoding to categorical features. section 9.3.2
- Concatenate processed features and pass them to ordinary Dense and Dropout layers. section 9.3.2
Table 9.1 Comparison of the Kuala Lumpur real solutions using custom classes and using Keras preprocessing layers (view table figure)
| Using custom layers |
Using Keras preprocessing layers |
|
|---|---|---|
| Pipeline |
Custom pipeline classes based on Scikit-learn Pipeline class (https://mng.bz/pKP5); requires classes to be defined in a separate file so they can be used at training and inference (https://mng.bz/OBxK); complex code to define, train, invoke, and save the pipelines. |
The standard, off-the-shelf Keras preprocessing layers, available at https://mng.bz/YD1o. The code to define, train, and invoke the pipeline is much simpler and more robust. |
| Model definition |
A complex set of layers, specified to work with categorical, continuous, and text inputs |
A simple set of layers, capable of working with generic categorical and continuous inputs |
Compare custom-layer pipelines with Keras preprocessing layers across pipeline complexity and model-definition simplicity. section 9.3.1
Kuala Lumpur property-price prediction
A property-price model separates continuous columns such as Bathrooms, Car Parks, Rooms, and Size from categorical columns such as Location, Property Type, Furnishing, and Size_type_bin. Preprocessing layers normalize the continuous columns, encode the categorical columns, and feed the combined representation into a compact neural network. Rename columns to lowercase snake_case before saving the model, because spaces and uppercase names can cause saving errors. section 9.3.2
