Skip to main content

This package provides helper utilities for machine learning tasks. One major utility is calculation of weight of evidence

Project description

Machine Learning Helper

This package usage multiple algorithms and parameters to accomodate different set of use cases to help in creating multiple machine learning algorithms.

1.0 woe (Weight of Evidence):

This function will help to calculate Weight of Evidence and Information Value, the charts can be displayed and coarse classing can also be done.

1.1 Parameters:


  • max_bin: int Maximum number of bins for numeric variables. The default is 10
  • iv_threshold: float Threshold value for Information Value. Variables with higher than threshold will be considered for transformation
  • ignore_threshold: Boolean This parameter controls whether the defined threshold should be considered or ignored. The default is 'True'

1.2 Returns:

DataFrame having weight of evidence of each column along with the target variable


1.3 Approach:

  1. Create an instance of woe my_woe = woe()

  2. Call fit method on the defined object by passing on dataframe and the target variable name my_woe.fit(df,target)

  3. Call the transform method transformed_df = my_woe.transform()


Example

Create Sample DataFrame

from mlh import woe
import pandas as pd
import numpy as np
import random

seed=1456
np.random.seed(seed)
random.seed(seed)
rows = 1000
y = random.choices([0,1],k=rows,weights=[.7,.3])
x1 = random.choices(np.arange(20,40),k=rows)
x2 = np.random.randint(1000,2000,size=rows)
x3 = random.choices(np.arange(1,100),k=rows)
x4 = random.choices(['m','f','u'],k=rows)
x5 = random.choices(['a','b','c','d','e','f','g','h'],k=rows)
df = pd.DataFrame({'y':y,'x1':x1,'x2':x2,'x3':x3,'x4':x4,'x5':x5})
df.head()

Fitting and prediction

Create Instance of Weight of Evidence Package

my_woe = woe()

Fit the data with created instance

my_woe.fit(df,'y')

Display the relevant charts

my_woe.getWoeCharts()

Merge values of X3 Variable at 1 and 2 indices using the Weight of Evidence chart from the first Iteration

my_woe.reset_woe(2,(1,2),1)

Get latest Iteration Information Value

my_woe.get_IV()

Replace the original values in the Dataframe with Weight of Evidence

transformed_df = my_woe.transform()

Project details


Download files

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

Source Distribution

mlh-0.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

mlh-0.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mlh-0.0.1.tar.gz.

File metadata

  • Download URL: mlh-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for mlh-0.0.1.tar.gz
Algorithm Hash digest
SHA256 861ada808b6a64b25ff018e71f24969668ed9feeb811fd063e2fcc8d5d7c3957
MD5 9f03913928c48069e4aa9c34d43cd89e
BLAKE2b-256 8dd768b2d4c7306b1381b607f6ef9e41b4827bb5b807f3157df0f4512bcae1d1

See more details on using hashes here.

File details

Details for the file mlh-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mlh-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for mlh-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 709803b2caefc30b5d21c16d086b5350b03563eb0fc5fc071ee46ce61e2148bb
MD5 8ea2436586ee90a4802a297242b71d6f
BLAKE2b-256 f80d4ec3333ca1fd258a7aa9dce47856ceae3a2a42a14294171db113bd3d20fc

See more details on using hashes here.

Supported by

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