Skip to content

Special values

You might have some features with values that you need to have in a separate bucket. You can define a dictionary with the buckets you want, and pass them to the bucketer.

In the example below, the special values for the variable "EDUCATION" are put into a separate bucket, -3. Note that this bucket is not included in the n_bins parameter

from skorecard.bucketers import EqualWidthBucketer
from skorecard.datasets import load_uci_credit_card

X, y = load_uci_credit_card(return_X_y=True)

specials = {
    "LIMIT_BAL": {"=50000": [50000], "in [20001,30000]": [20000, 30000]},
    "EDUCATION": {"=High School, Graduate School": [1, 3]}

X_transformed = EqualWidthBucketer(n_bins=3, specials=specials, variables=cols).fit_transform(X, y)
-3    3199
 0    2726
 2      62
 1      13
Name: EDUCATION, dtype: int64

Last update: 2021-11-24
Back to top