DecisionTreeBucketer
Bases: BaseBucketer
The DecisionTreeBucketer
transformer creates buckets by training a decision tree.
Support:
It uses sklearn.tree.DecisionTreeClassifier to find the splits.
Example:
from skorecard import datasets
from skorecard.bucketers import DecisionTreeBucketer
X, y = datasets.load_uci_credit_card(return_X_y=True)
# make sure that those cases
specials = {
"LIMIT_BAL":{
"=50000":[50000],
"in [20001,30000]":[20000,30000],
}
}
dt_bucketer = DecisionTreeBucketer(variables=['LIMIT_BAL'], specials = specials)
dt_bucketer.fit(X, y)
dt_bucketer.fit_transform(X, y)['LIMIT_BAL'].value_counts()
Source code in skorecard/bucketers/bucketers.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
|
variables_type
property
¶
Signals variables type supported by this bucketer.
__init__(variables=[], specials={}, max_n_bins=100, missing_treatment='separate', min_bin_size=0.05, random_state=None, remainder='passthrough', get_statistics=True, dt_kwargs={})
¶
Init the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variables |
list
|
The features to bucket. Uses all features if not defined. |
[]
|
specials |
dict
|
dictionary of special values that require their own binning.
The dictionary has the following format:
{" |
{}
|
min_bin_size |
float
|
Minimum fraction of observations in a bucket. Passed directly to min_samples_leaf. |
0.05
|
max_n_bins |
int
|
Maximum numbers of after the bucketing. Passed directly to max_leaf_nodes of the DecisionTreeClassifier. If specials are defined, max_leaf_nodes will be redefined to max_n_bins - (number of special bins). The DecisionTreeClassifier requires max_leaf_nodes>=2: therefore, max_n_bins must always be >= (number of special bins + 2) if specials are defined, otherwise must be >=2. |
100
|
missing_treatment |
str or dict
|
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'
|
random_state |
int
|
The random state, Passed directly to DecisionTreeClassifier |
None
|
remainder |
str
|
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'
|
dt_kwargs |
Other parameters passed to DecisionTreeClassifier |
{}
|
Source code in skorecard/bucketers/bucketers.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|