<jupyter_start><jupyter_text>Hashing one feature<jupyter_code># set up the feature hashing encoder to encode
# one variable in the dataframe

encoder = HashingEncoder(cols=["A7"], n_components=4)
# fit the transformer to the train set

encoder.fit(X_train)
# the hashing method used

encoder.hash_method
# We can find the algorithms available for hashing
# in the hashlib library

import hashlib

hashlib.algorithms_available
# let's transform train and test sets

X_train_enc = encoder.transform(X_train)
X_test_enc = encoder.transform(X_test)
# We see the hashed features at the left of the dataframe

X_train_enc.head()
# We see the hashed features at the left of the dataframe

X_test_enc.head()<jupyter_output><empty_output><jupyter_text>Multivariate hashingCategory Encoders will hash all categorical variables to the same 4 columns by default. It is like "multivariate" hashing.<jupyter_code>encoder = HashingEncoder(cols=["A5", "A7", "A12", "A14"], n_components=4)
# fit the transformer to the train set

encoder.fit(X_train)
# let's transform train and test sets

X_train_enc = encoder.transform(X_train)
X_test_enc = encoder.transform(X_test)
# We see the hashed features at the left of the dataframe

# Now we see that the values can take numbers beyond 1
# which means that 2 or more variables were assigned
# to the same feature

X_train_enc.head()
X_test_enc.head()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup