Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

Optimal Binning - How to implement a few variables to function from DataFrame in Python Pandas?

Hellow! How can I calculate Optimal Binning in Python for the list of variables, not only for one variable ?

I havce example DataFrame like below:

df = pd.DataFrame({"var1" : ["a", "b"], "var2" : ["c", "d"], "var3" : ["e", "f"]})

For instance I have function like below:

def OBin(df, target, rest_variabls, dtypes):

    #Data
    x = df_abt[rest_variabls].values
    y = df_abt[target]
    #WoE
    optb = OptimalBinning(name=df, dtype=dtypes, solver="cp")
    optb.fit(x, y)
    optb.binning_table.build()

And when I want to use this function like below:

OBin(df, "target", ["var1", "var2"], "categorical")

Neverteless I have type error like below in optb.fit(x, y), how can I do ? Types of var1 and var2 is object.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...