画子图,查看分布对比图
data_temp = data
# 分布对比图deffea_diff(label,fea,fea_name,bins,ran,ran_limit,log):
data = pd.DataFrame({'fea':fea,'label':label})#nrows, ncols : int, optional, default: 1 Number of rows/columns of the subplot grid.#True or 'all': x- or y-axis will be shared among all subplots.
fig,(ax0,ax1)= plt.subplots( nrows=2,sharex=True,figsize =(12,8))#调整子图位置
plt.subplots_adjust(hspace=0)
data = data.fillna(0)if ran_limit==False:
ran =[min(data.fea),max(data.fea)]#画直方图 #x : (n,) array or sequence of (n,) arrays # bins : int or sequence or str, optional
ax0.hist(data.loc[(data.label==1),'fea'],bins=bins,alpha=0.5,range=ran,normed =False,log=True)
ax0.set_ylabel('count',fontsize=20)
ax0.legend(['label = 1'],loc =9,fontsize=20)
ax0.tick_params(labelsize =20)
ax0.grid()
ax1.hist(data.loc[(data.label==0),'fea'],color='r',bins=bins,alpha=0.5,range=ran,normed =False,log=True)
ax1.set_xlabel(fea_name,fontsize=20)
ax1.set_ylabel('count',fontsize=20)
ax1.legend(['label = 0'],loc =9,fontsize=20)
ax1.tick_params(labelsize =20)
ax1.grid()
fea_diff(label =(data_temp.loan_cur_balance<1000000),#标签列
fea = data_temp.loan_cur_balance,#特征列
fea_name ='loan_cur',#特征名
bins =50,#分桶数
ran_limit=False,#是否启用范围限制
ran =[0,0],#数据范围
log =False#是否对纵轴取对数)