Skip to main content

The missing scikit-learn addition to work with Weight-of-Evidence scoring.

Project description

image

pywoe [Beta]

The missing scikit-learn addition to work with Weight-of-Evidence scoring, with a special focus on credit risk modelling. There's evidently a lack of open source, free-to-use, well-tested Python package for basic credit risk modelling tasks. Such a package should provide easily serialisable, deployable, transferable data validation, feature engineering and feature selection techniques. It should also be easy to use within the Jupyter Lab framework.

This is still very much a work-in-progress, and the package can be extended in multiple useful ways. Feel free to contribute.

Table of Contents

  1. Installation
  2. Usage Examples
  3. Further Work

Installation

To install the latest version of the package, simply run

pip install pywoe

Usage Examples

Introduction

For easy start, there's a ready-made sklearn pipeline provided. To load, do the following. Feel free to run the pipeline on example data, as below.

from pywoe.interface import get_raw_data_to_woe_values_pipeline
from sklearn.datasets import load_breast_cancer

pipeline = get_raw_data_to_woe_values_pipeline()
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
pipeline.fit(X, y)
woe_transformed = pipeline.transform(X)

The setup above automatically constructs bins and computes WoE across them. The output can be used to select features for a logistic regression model, or to preprocess features before entering them to a model.

Informaton Values (IV)

In the example above, Information Values have also been computed. To retrieve them alongside the binning decided for a feature mean radius, do:

pipeline['woe_transformer'].woe_spec['mean radius'].bins

and you'll see the values printed out.

Inspecting Default Settings

from pywoe import constants

constants.NUMERIC_ACCURACY
constants.DEFAULT_DECISION_TREE_CLASSIFIER_FIT_KWARGS
constants.DEFAULT_DECISION_TREE_CLASSIFIER_INIT_KWARGS
constants.P_VALUE_THRESHOLD

Overriding Defaults

from sklearn.pipeline import Pipeline
from pywoe.feature_engineering.validator import FeatureValidator
from pywoe.feature_engineering.binning import DecisionTreeBinner
from pywoe.feature_engineering.woe import WoETransformer

feature_validator = FeatureValidator()
binner = DecisionTreeBinner(
    feature_validator=feature_validator,
    init_kwargs={
        "criterion": "entropy",
        "max_depth": 3,
        "min_samples_leaf": 0.2
    }
)
woe_transformer = WoETransformer(binner=binner)

# Keep in mind `binner` is not an `sklearn` object, it is a parameter 
# to `woe_transformer`, so it's not used in the pipeline.
pipeline = Pipeline([
    ('validator', feature_validator),
    ('woe_transformer', woe_transformer)
])

Further Work

Further work needed includes, but is not limited to:

  • (significantly) improving testing,
  • adding marginal-IV-based automated feature selection,
  • adding Jupyter-integrated plotting capabilities to inspect models,
  • adding residual monitoring (ReMo) capabilities,
  • ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywoe-0.0.2-py2-none-any.whl (20.9 kB view details)

Uploaded Python 2

File details

Details for the file pywoe-0.0.2-py2-none-any.whl.

File metadata

  • Download URL: pywoe-0.0.2-py2-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3

File hashes

Hashes for pywoe-0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 37294813c2c196d5e399015b7c339be91c6aefc0d17ed635fc86b07258f40cf8
MD5 6fb59cce4078f50e1867670f599db4a5
BLAKE2b-256 d97d455690f7a4fc12446d5f95c2b34f7ff859381e0c653874f3f04aa274d495

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page