EqualWidthBucketer
Bases: BaseBucketer
The EqualWidthBucketer
transformer creates equally spaced bins using numpy.histogram
function.
Support:
Example:
from skorecard import datasets
from skorecard.bucketers import EqualWidthBucketer
specials = {"LIMIT_BAL": {"=50000": [50000], "in [20001,30000]": [20000, 30000]}}
X, y = datasets.load_uci_credit_card(return_X_y=True)
bucketer = EqualWidthBucketer(n_bins = 10, variables = ['LIMIT_BAL'], specials=specials)
bucketer.fit_transform(X)
bucketer.fit_transform(X)['LIMIT_BAL'].value_counts()
Source code in skorecard/bucketers/bucketers.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
variables_type
property
¶
Signals variables type supported by this bucketer.
__init__(n_bins=5, variables=[], specials={}, missing_treatment='separate', remainder='passthrough', get_statistics=True)
¶
Init the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_bins |
int
|
Number of bins to create. |
5
|
variables |
list
|
The features to bucket. Uses all features if not defined. |
[]
|
specials |
(dict) of special values that require their own binning.
The dictionary has the following format:
{" |
{}
|
|
missing_treatment |
Defines how we treat the missing values present in the data.
If a string, it must be one of the following options:
separate: Missing values get put in a separate 'Other' bucket: |
'separate'
|
|
remainder |
How we want the non-specified columns to be transformed. It must be in ["passthrough", "drop"]. passthrough (Default): all columns that were not specified in "variables" will be passed through. drop: all remaining columns that were not specified in "variables" will be dropped. |
'passthrough'
|
Source code in skorecard/bucketers/bucketers.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|