Skip to content

To skorecard pipeline

Transform a scikit-learn Pipeline to a SkorecardPipeline.

A SkorecardPipeline is a normal scikit-learn pipeline with some extra methods and attributes.

Example:

from skorecard.pipeline.pipeline import SkorecardPipeline, to_skorecard_pipeline
from skorecard.bucketers import DecisionTreeBucketer, OrdinalCategoricalBucketer
from skorecard import datasets

from sklearn.pipeline import make_pipeline

pipe = make_pipeline(
    DecisionTreeBucketer(variables = ["LIMIT_BAL", "BILL_AMT1"],max_n_bins=5),
    OrdinalCategoricalBucketer(variables = ["EDUCATION", "MARRIAGE"], tol =0.05)
)
sk_pipe = to_skorecard_pipeline(pipe)

df = datasets.load_uci_credit_card(as_frame=True)

features = ["LIMIT_BAL", "BILL_AMT1", "EDUCATION", "MARRIAGE"]
X = df[features]
y = df["default"].values

Parameters:

Name Type Description Default
pipeline Pipeline

scikit-learn pipeline instance.

required

Returns:

Name Type Description
pipeline SkorecardPipeline

modified pipeline instance.

Source code in skorecard/pipeline/pipeline.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
def to_skorecard_pipeline(pipeline: Pipeline) -> SkorecardPipeline:
    """
    Transform a scikit-learn Pipeline to a SkorecardPipeline.

    A SkorecardPipeline is a normal scikit-learn pipeline with some extra methods and attributes.

    Example:

    ```python
    from skorecard.pipeline.pipeline import SkorecardPipeline, to_skorecard_pipeline
    from skorecard.bucketers import DecisionTreeBucketer, OrdinalCategoricalBucketer
    from skorecard import datasets

    from sklearn.pipeline import make_pipeline

    pipe = make_pipeline(
        DecisionTreeBucketer(variables = ["LIMIT_BAL", "BILL_AMT1"],max_n_bins=5),
        OrdinalCategoricalBucketer(variables = ["EDUCATION", "MARRIAGE"], tol =0.05)
    )
    sk_pipe = to_skorecard_pipeline(pipe)

    df = datasets.load_uci_credit_card(as_frame=True)

    features = ["LIMIT_BAL", "BILL_AMT1", "EDUCATION", "MARRIAGE"]
    X = df[features]
    y = df["default"].values
    ```

    Args:
        pipeline (Pipeline): `scikit-learn` pipeline instance.

    Returns:
        pipeline (skorecard.pipeline.SkorecardPipeline): modified pipeline instance.
    """
    assert isinstance(pipeline, Pipeline)
    if isinstance(pipeline, SkorecardPipeline):
        return pipeline
    else:
        return SkorecardPipeline(steps=pipeline.steps, memory=pipeline.memory, verbose=pipeline.verbose)