This package usage multiple algorithms and parameters to accomodate different set of use cases to help in creating multiple machine learning algorithms.
This function will help to calculate Weight of Evidence and Information Value, the charts can be displayed and coarse classing can also be done.
- 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'
DataFrame having weight of evidence of each column along with the target variable
-
Create an instance of woe my_woe = woe()
-
Call fit method on the defined object by passing on dataframe and the target variable name my_woe.fit(df,target)
-
Call the transform method transformed_df = my_woe.transform()
from mlh import woe
import pandas as pd
import numpy as np
import random
seed=1456
np.random.seed(seed)
random.seed(seed)rows = 1000y = 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()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()