Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created April 17, 2024 09:42
Show Gist options
  • Select an option

  • Save simonespa/2347de028788ee2eba1d286ea15ec4e7 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/2347de028788ee2eba1d286ea15ec4e7 to your computer and use it in GitHub Desktop.
from category_encoders import HashingEncoder
N = unique[column]
encoder = HashingEncoder(
cols=[column],
n_components=math.ceil(math.log2(N)), # the number of bits required to encode N elements
hash_method='sha256' # https://docs.python.org/3/library/hashlib.html#constructors
)
df = encoder.fit_transform(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment