Skip to content

Instantly share code, notes, and snippets.

@rdisipio
Created November 6, 2022 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdisipio/468d703186bd858282735f739788e6cb to your computer and use it in GitHub Desktop.
Save rdisipio/468d703186bd858282735f739788e6cb to your computer and use it in GitHub Desktop.
from sklearn.preprocessing import KBinsDiscretizer
n_bins = 10 # the more, the merrier
scaled_feature_names = [f"q_{x}" for x in feature_names]
qt = KBinsDiscretizer(n_bins=n_bins, encode='ordinal', strategy='quantile')
X_qt = qt.fit_transform(X).astype(np.int32) # nb: bin number must be an integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment