AgglomerativeClusteringBucketer
Bases: BaseBucketer
The AgglomerativeClusteringBucketer
transformer creates buckets using sklearn.AgglomerativeClustering.
Support
Example:
from skorecard import datasets
from skorecard.bucketers import AgglomerativeClusteringBucketer
specials = {"LIMIT_BAL": {"=50000": [50000], "in [20001,30000]": [20000, 30000]}}
X, y = datasets.load_uci_credit_card(return_X_y=True)
bucketer = AgglomerativeClusteringBucketer(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
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
variables_type
property
¶
Signals variables type supported by this bucketer.
__init__(n_bins=5, variables=[], specials={}, missing_treatment='separate', remainder='passthrough', get_statistics=True, **kwargs)
¶
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'
|
|
kwargs |
Other parameters passed to AgglomerativeBucketer |
{}
|
Source code in skorecard/bucketers/bucketers.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|