python ks值,ks检验正态分布p值

  python ks值,ks检验正态分布p值

  更多大数据分析、建模等内容请关注公众号《bigdatamodeling》/件蟒蛇皮实现偷杀/抢杀曲线,相关使用方法请参考上篇博客-R语言实现偷杀/抢杀曲线

  # # # # # # # # # # # # # # # # # # # # # # # # def PlotKS(preds,labels,n,ASC):# preds is score:ASC=1 # preds is prob:ASC=0 pred=preds #预测值错误=标签#取一为坏,0为good ksds=DataFrame({bad: bad, pred :pred })ksds[ good ]=1-ksds。如果ASC==1:ksds 1=ksds,则为不良。sort _ values(by=[ pred , bad],ascending=[True,True])elif ASC==0:ksds 1=ksds。sort _ values(by=[ pred , bad],ascending=[False,True])ksds 1。索引=范围(长度(ksds 1。pred False])elif ASC==0:ksds 2=ksds。sort _ values(by=[ pred , bad],ascending=[False,False])ksds 2。索引=范围(长度(ksds 2。pred))ksds 2[ cumsum _ good 2 ]=1.0 * ksds 2。很好。cumsum()/sum(ksds 2。good)ksds 2[ cumsum _ bad 2 ]=1.0 * ksds 2。不好。cumsum()/sum(ksds 2).as type(int)ks _ index=list(ks _ index)ksds=ksds。loc[ks _ index]ksds=ksds[[ tile , cumsum_good , cumsum_bad , ks]] ksds0=np.array([[0,0,0,0]]) ksds=np.concatenate([ksds0,ksds],axis=0) ksds=DataFrame(ksds,columns=[tile , cumsum_good , cumsum_bad , ks ])ks _ value=kss cumsum_good],color=blue ,line style=-)plsaxh线(ksds。loc[ksds。KS。idx max(), cumsum_bad],color=red ,line style=-)PLT。标题( KS=% s % NP。round(KS _ value,4) at Pop=%s %np.round(ks_pop,4),font size=15)返回ksds # # # # # # # # # # # # # # # # # #作图如下:

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: