'Unexpected Number of Weights in tf.keras Sequential Model
I have a question about the predictive power of each feature so I need a way to evaluate how strong each feature is in the final model. My feature_layer contains two indicator_columns wrapped around categorical_column_with_vocabulary_lists for categorical data, an indicator_column wrapped around a cross between two bucketized numerical columns for latitude/longitude data, and five numeric columns.
I would expect the finished model to have 15 weights: 2 for the latitude and longitude, 5 for the numeric columns, and 5 and 3 for each of the categorical columns using one-hot encoding. However, len(model.get_weights())[0] returns 513. I suspect the latitude and longitude have many more weights since a cross between two bucketized columns ends up being a sparse categorical feature with a high enough resolution. However, assuming this is true, I still don't know how to interpret the weights returned by model.get_weights()[0].
Solution 1:[1]
I found out that the answer has to do with the hash_bucket_size argument in the crossed_column. Each of those hashes gets a weight of its own in the final model. The 513 weights were a result of the 13 weights from every other feature and the 500 hashes for the crossed latitude/longitude.
In terms of interpreting the weights, I am under the assumption that the weights of the model remain in the order that I added features to the feature_layer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ethan Colby-Witanek |
