<jupyter_start><jupyter_text>KBinsDiscretizer<jupyter_code># discretize numeric input variables
from sklearn.datasets import make_classification
from sklearn.preprocessing import KBinsDiscretizer
import pandas as pd
# define dataset
X, y = make_classification(n_samples=10000000, n_features=5, n_informative=5, n_redundant=0, random_state=1)
# n_informative=5, n_redundant=0,
X.shape
y.shape
X[0,:]
# summarize data before the transform
print(X[:3, :])
y.mean()
X.min()
X.max()
# define the transform
trans = KBinsDiscretizer(n_bins=10, encode='ordinal', strategy='uniform')
# transform the data
X_discrete = trans.fit_transform(X)
X[0, :]
print(X_discrete[0, :])
X[1, :]
# summarize data after the transform
print(X_discrete[1, :])
data = pd.DataFrame(X)
data.describe().round(2)
data.iloc[0,:]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1321212121212121, 'fraction_numerical': 0.02909090909090909, 'mean_word_length': 7.978260869565218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '300320', 'license': 'MIT', 'n_tokens_mistral': 327, 'n_tokens_neox': 305, 'n_words': 65, 'path': 'Preprocessing/KBinsDiscretizer1.ipynb', 'repo_name': 'skawns0724/KOSA-Big-Data_Vision', 'size': '825'}