In machine learning, feature hashing (also called hashing trick) is an efficient way to encode categorical features. It is based on hashing functions in computer science that map data of variable sizes to data of a fixed (and usually smaller) size. It is easier to understand feature hashing through an example.
Let's say we have three features—gender, site_domain, and device_model, for example:
With one-hot encoding, this will become feature vectors of size 9, which come from 2 (from gender) + 4 (from site_domain) + 3 (from device_model). With feature hashing, we want to obtain a feature vector of size 4. We define ...