from sklearn.model_selection import train_test_split
train,test=train_test_split(dd,test_size=0.6)
toad.detect(dd)
toad.quality(dd,target='target',iv_only=False)
train_selected,dropped =toad.selection.select(train,target = 'target',empty = 0.85, iv = 0.01, corr = 0.8, return_drop=True)
print(dropped)
print(train_selected.shape)
c=toad.transform.Combiner()
train_selected
c.fit(train_selected,y="target",method="chi",min_samples=0.05,empty_separate=False)
print(c.export())
from toad.plot import bin_plot
col='申请人手机号与银行预留手机号是否一致'
bin_plot(c.transform(train_selected[[col,'target']],labels=True),x=col,target='target')
rule={'水寒分':[0,435,633,745]}
c.update(rule)
bin_plot(c.transform(train_selected[['水寒分','target']],labels=True),x='水寒分',target='target')
transer=toad.transform.WOETransformer()
train_woe=transer.fit_transform(c.transform(train_selected),train_selected['target'],
exclude='target')
test_woe=transer.transform(c.transform(test))
final_data=toad.selection.stepwise(train_woe,
target='target',estimator='ols',direction='both',
criterion='aic')
final_test=test_woe[final_data.columns]
print(final_data.shape)
final_test
final_data
card=toad.ScoreCard(combiner =c,
transer = transer,base_score = 700,C=0.1)
card.fit(final_data[col],final_data['target'])
card.export()
card.export()
import pandas as pd
card.predict(dd)