Skip to main content

woe

woe is a Python library designed to convert categorical and continuous variables into weight of evidence. Weight of evidence is a statistical technique used in information theory to measure the "strength" of a relationship between a binary target variable and a predictor variable. The library can be used for data preprocessing in predictive modeling or machine learning projects.

installation

pip3 install woe-conversion

usage

from woe_conversion.woe import *

# create an instance of the WoeConversion class
woemodel = WoeConversion(binarytarget='survived', features=['categorical_variable_1','categorical_variable_2','continuous_variable_3'])

# fit the model using training data (train is a pandas dataframe)
woemodel.fit(train)

# transform the training and test data using the fitted model (train and test are pandas dataframes)
transformedtrain = woemodel.transform(train)
transformedtest = woemodel.transform(test)

In the above code, WoeConversion is the class that is used to perform the conversion of variables to weight of evidence. The binarytarget parameter is the name of the binary target column in your dataset, and features is a list of the columns that you want to convert to weight of evidence.

Once the model has been created, it is fit to the training data using the fit method. This method calculates the weight of evidence for each category in the specified columns, and stores the results in the model object.

The transform method is then used to transform the training and test data using the fitted model. This method replaces the original columns with their weight of evidence equivalents.

Note on Missing Values

The weight of evidence is also calculated for missing values. Therefore, missing values should not be imputed before calling the woe model.

Full working example

from woe_conversion.woe import *
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

titanic = sns.load_dataset('titanic')
train, test = train_test_split(titanic, test_size=0.30,random_state=111,stratify=titanic['survived'])

woemodel = WoeConversion(binarytarget='survived', features=['age','sex','class','fare'])
woemodel.fit(train)

clf = LogisticRegression()
clf.fit(woemodel.transform(train)[['age','sex','class','fare']], train['survived'])

train['proba'] = clf.predict_proba(woemodel.transform(train)[['age','sex','class','fare']])[:,1]
test['proba'] = clf.predict_proba(woemodel.transform(test)[['age','sex','class','fare']])[:,1]

Author

woe was created by Bertrand Brelier. If you have any questions or issues, please feel free to contact the author.

Metadata

Release files for woe-conversion 0.3.0

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

Source distribution (sdist)

Source distribution for woe-conversion 0.3.0
File Size Uploaded Provenance Actions
woe_conversion-0.3.0.tar.gz 5.8 kB Without provenance Details for woe_conversion-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for woe-conversion 0.3.0
File Interpreter ABI Platform Actions
woe_conversion-0.3.0-py3-none-any.whl Python 3 none any Details for woe_conversion-0.3.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / woe_conversion-0.3.0.tar.gz

Download URL woe_conversion-0.3.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d45c4582f3d07128e59c02d7931bdc837ca5cb47096b7345585f8a480ad0a6af
BLAKE2b-256 checksum
How to use checksums
45fe69deea8a3452e4f9f959a357375cab8b6914e8355317844069524be7bed1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / woe_conversion-0.3.0-py3-none-any.whl

Download URL woe_conversion-0.3.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1be00fe85b03d61aeebbad2d5323b2103b04092e5616f36f553349b008e11d69
BLAKE2b-256 checksum
How to use checksums
4a769975dac95b4bd06841ba9d809e5c629a6b8fc7606ea17c5fe4f8668ea514
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for woe-conversion 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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