Skip to main content

# woeBinningPandas This code generates a supervised fine and coarse classing of numeric variables and factors with respect to a dichotomous target variable. Its parameters provide flexibility in finding a binning that fits specific data characteristics and practical needs.

The basis of this code was taken woeBinning code (https://github.com/cran/woeBinning/blob/master/R/woe.binning.R) and changed from R to Python. # Used programs versions Spyder (Python 3.7)

Pandas 0.23.4 # Used Python libraries import pandas as pd

import numpy as np

import math

import warnings

import copy # Using ### Cloning a repository from GitHub #### Use Git CMD

>cd YOUR LINK FOLDER

>git clone https://github.com/V1ad98/woeBinningPandas.git

#### File woeBinningPandas is ready to go! ### Set your variable CSV file > yourvariable = pd.read_csv(‘Yourfile.csv’) ### Set the df variable and specify the column names from your CSV file, which you want to use. > df = yourvariable[[‘columnnames1’, ‘columnnames2’,’columnnames3’]] ### At THE END of the code in the function call woe_binning set the values of the arguments > binning = woe_binning(df, target_var, pred_var, min_perc_total, min_perc_class, stop_limit, abbrev_fact_levels, event_class)

df - Name of data frame with input data.

target_var - Name of dichotomous target variable in quotes. Only target variables with two distinct values (0 or 1).

pred_var - Name of predictor variables to be binned in quotes. Values can be either numeric or factors.

min_perc_total - For numeric variables this parameter defines the number of initial classes before any merging is applied. WOE starts. Increasing the min_perc_total} parameter will avoid sparse bins. Accepted range: 0.0001-0.2; default: 0.05.

min_perc_ class - If a column percentage of one of the target classes within a bin is below this limit (e.g. below 0.01=1%) then the respective bin will be joined with others. In case of numeric variables adjacent predictor classes are merged. Setting min_perc_class > 0 may provide more reliable WOE values. Accepted range: 0-0.2; default: 0, i.e. no merging with respect to sparse target classes is applied.

stop_limit - Stops WOE based merging of the predictor’s classes/levels in case the resulting information value (IV) decreases more than (e.g. 0.05 = 5%) compared to the preceding binning step. stop_limit=0 will skip any WOE based merging. Increasing the stop_limit will simplify the binning solution and may avoid overfitting. Accepted range: 0-0.5; default: 0.1.

abbrev_fact_levels - Abbreviates the names of new (merged) factor levels via the base abbreviate function in case the specified number of characters is exceeded.

event_class - Optional parameter for specifying the class of the target event. This class typically indicates a negative event like a loan default or a disease. Use characters in quotes (e.g. bad). This class will be represented by negative WOE values then. # Using with PIP package ### Download PIP package woeBinningPandas > pip install woeBinningPandas ### Add use package > import woeBinningPandas ### Set variables and call a function > yourvariable = woeBinningPandas.pd.read_csv(‘Yourfile.csv’)

> df = yourvariable[[‘columnnames1’, ‘columnnames2’,’columnnames3’]] ### Pass your values to functions > binning = woeBinningPandas.woe_binning (df, target_var, pred_var, min_perc_total, min_perc_class, stop_limit, abbrev_fact_levels, event_class) # Examples > import woeBinningPandas

> germancredit = woeBinningPandas.pd.read_csv(‘GermanCredit.csv’)

> df = germancredit[[‘credit_risk’, ‘amount’,’duration’]]

> binning = woeBinningPandas.woe_binning(df, ‘credit_risk’, ‘duration’, 0.05, 0, 0.1, 50, ‘bad’)

Release files for woeBinningPandas 1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for woeBinningPandas 1.9
File Size Uploaded
woeBinningPandas-1.9.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for woeBinningPandas 1.9
File Interpreter ABI Platform
woeBinningPandas-1.9-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / woeBinningPandas-1.9.tar.gz

Download URL woeBinningPandas-1.9.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c8b1309d6e0ba6805adb709e4c71078393aa1f431c0a26d9a6aae2bc36c9d2a
BLAKE2b-256 checksum
How to use checksums
201a25dbd97cb1b5bec41877dc45c166040537df1280ea7d3621f82ea9982d95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / woeBinningPandas-1.9-py3-none-any.whl

Download URL woeBinningPandas-1.9-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34cb081e0ff60e758be76d3b748ee0222c4468055da0f695da8f886104f598ca
BLAKE2b-256 checksum
How to use checksums
01acc77aef4de9dbe5c218f7b3b3a15fd7dee65413f8abb3aeaa501df3a47da5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.9 This release

2 release files

1.8

2 release files

1.7

1 release file

1.6

1 release file

1.5

1 release file

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page