画lift曲线
target=np.array([1,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,1,0,0,1])
y_pre=np.random.rand(20)
y_pre
def lift(target,y_pre):
data=pd.DataFrame({'target':target,'y_pre':y_pre})
data['y_pre']=pd.qcut(data['y_pre'],q=[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
data=data.groupby('y_pre').sum().reset_index()
data['apply']=1
data['cum_bad']=data['target'].cumsum()
data['cum_apply']=data['apply'].cumsum()
data['bad_total']=data['target'].sum()
data['apply_total']=data['apply'].sum()
data['cum_bad_rate']=data['cum_bad']/data['bad_total']
data['cum_apply_rate']=data['cum_apply']/data['apply_total']
data['lift']=data['cum_bad_rate']/data['cum_apply_rate']
return np.array(data['lift'])