0

I am trying to replace all the columns in a Pandas data frame with respective woe values.

I calculated woe values in a separate function.

I have variable, bin, binedges, WOE in one data frame and in the main data frame.

I have customer_id and the rest of independent varaibles, i have replace the independent varaible values with respective woe values.

Can any one please help?

Pmpr.ir
  • 16,260
  • 23
  • 83
  • 97
  • 2
    Welcome to SO. Please take a tour of [how-to-make-good-reproducible-pandas-examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Shubham Sharma Jun 12 '20 at 10:22
  • There is a sklearn style transformer available here: http://contrib.scikit-learn.org/category_encoders/woe.html but I would double check the results for correctness – Dan Jun 12 '20 at 10:23

1 Answers1

1

You can use the xverse package in python for this.

First of all install the xverse package using Anaconda Prompt:

pip install xverse

Note: I'm also showing how to make bins.

Then import MonotonicBinning from the xverse package in your notebook and make bins.

from xverse.transformer import MonotonicBinning

clf = MonotonicBinning()
clf.fit(X, y)
output_bins = clf.bins

Where X is the set of features(of which you want to replace by woe values) as pandas Dataframe and y is the target variable in form of an array

Now store the bins in a separate dataset with the same column names:

X1 = clf.transform(X)

Now import WOE from the xverse package

from xverse.transformer import WOE
clf1 = WOE()
clf1.fit(X1, y)

X2 = clf1.transform(X1)

X2 is the required dataframe of features replaced by their respective woe values