群体稳定性指标PSI(Population Stability Index)是衡量模型的预测值与实际值偏差大小的指标。

PSI = sum((实际占比-预期占比)* ln(实际占比/预期占比))

举例:

比如训练一个logistic回归模型,预测时候会有个概率输出p。
测试集上的输出设定为p1吧,将它从小到大排序后10等分,如0-0.1,0.1-0.2,…。
现在用这个模型去对新的样本进行预测,预测结果叫p2,按p1的区间也划分为10等分。
实际占比就是p2上在各区间的用户占比,预期占比就是p1上各区间的用户占比。
意义就是如果模型跟稳定,那么p1和p2上各区间的用户应该是相近的,占比不会变动很大,也就是预测出来的概率不会差距很大。

一般认为PSI小于0.1时候模型稳定性很高,0.1-0.25一般,大于0.25模型稳定性差,建议重做。

PS:除了按概率值大小等距十等分外,还可以对概率排序后按数量十等分,两种方法计算得到的psi可能有所区别但数值相差不大。

以上转自:https://blog.csdn.net/Rango_lhl/article/details/81388051

以下用自己最近做的一个project的代码做个例子:

Load libraries and data
import pandas as pd
import numpy as np
import math
import re
# sample data
df = pd.read_csv('dev.csv')# holdout data(without target variable)
dfo = pd.read_csv('oot0.csv')
Define PSI function
def psi(bench, comp, group):
"""
bench: sample[variable]
comp: holdout[variable]
group: how many groups with in the variablesuggestion: group=max(2,min((len(set(df[var_name]))),10))at least 2,at max 10,so if continuous variable, it will be maximum at 10and if categorical variable with less than 10 cats, it will be number of categories
"""# get the number of rows of the sample and holdoutben_len=len(bench);comp_len=len(comp);# sort the valuesbench.sort();comp.sort();psi_cut=[];# calculate sample_size / number_groupsn=int(math.floor(ben_len/group));# from 1 to number_groupsfor i in range(1,group):# as bench has been sorted, we can get the spot of cutting edge values# for example i=1 ⇒ bench[1] will be the first lowercut# and bench[1*n] or bench[-1] will be the first uppercut# count how many values in each benchlowercut=bench[(i-1)*n+1];# when i < groupif i!=group:uppercut=bench[(i*n)];ben_cnt=n;# when i==group else:uppercut=bench[-1];ben_cnt=ben_len-group*(n-1)# count for values in corresponding intervals in holdout datasetcomp_cnt = len([i for i in comp if i > lowercut and i<=uppercut]);# calculate percentage of counts_in_interval / total_valuesben_pct=(ben_cnt+0.0)/ben_len;comp_pct=(comp_cnt+0.0)/comp_len;# if in the corresponding interval, there is value, calculate the psi for this intervalif comp_pct > 0.0:psi_cut.append((ben_pct-comp_pct)*math.log(ben_pct/(comp_pct)));else:psi_cut.append(0);# sum up all the psi, and check the totalpsi=sum(psi_cut);return psi;
Run the psi function to every input variable
list_inputs = list()
# get all the input variables
for var_name in df.columns:if re.search('^i',var_name):list_inputs.append(var_name)
# iter the function through them
for var_name in list_inputs:psi_value=psi(bench=list(df[var_name]),comp=list(dfo[var_name]),group=max(2,min((len(set(df[var_name]))),10)));print ("psi for ", var_name, " = ", psi_value)

群体稳定度指标PSI相关推荐

  1. 模型稳定度指标PSI

    群体稳定性指标PSI(Population Stability Index)是衡量模型的预测值与实际值偏差大小的指标. PSI = sum((实际占比-预期占比)* ln(实际占比/预期占比)) 举例 ...

  2. [机器学习] 模型稳定度指标PSI

    群体稳定性指标(population stability index) 由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(populati ...

  3. python计算模型psi_模型稳定度指标PSI与IV

    由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发 ...

  4. 模型稳定度指标PSI 释义及计算示例

    稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发样本评分的的分布差异,为最常见的模型稳定度评估指针.其实PSI表示的就是按分数分档后,针对不同样本, ...

  5. 模型稳定度指标PSI与IV

    由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发 ...

  6. 信用评分卡模型稳定度指标PSI

    由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发 ...

  7. 风控ML[13] | 特征稳定性指标PSI的原理与代码分享

    PSI这个指标我们在风控建模前后都是需要密切关注的,这个指标直接反映了模型的稳定性,对于我们评估模型是否需要迭代有着直接的参考意义.今天我将从下面几方面来介绍一下这个指标. Index 01 PSI的 ...

  8. ML之ME/LF:机器学习之风控业务中常用模型评估指标PSI(人群偏移度指标)的的简介、使用方法、案例应用之详细攻略

    ML之ME/LF:机器学习之风控业务中常用模型评估指标PSI(人群偏移度指标)的的简介.使用方法.案例应用之详细攻略 目录 PSI(稳定度指标)的简介 1.如何计算PSI? (1).PSI计算过程

  9. 模型稳定性指标—PSI

    由于模型是以特定时期的样本所开发的,此模型是否适用于开发样本之外的族群,必须经过稳定性测试才能得知.稳定度指标(population stability index ,PSI)可衡量测试样本及模型开发 ...

  10. 小白如何写Python算法-计算模型稳定性评估指标PSI

    前言 最近在研究如何存储和查询十亿数据的事情突然插了一档子事公司让我临时救个

最新文章

  1. Open3d 学习计划—13(Azure Kinect)
  2. Godaddy如何导入导出MSSQL数据库
  3. sdwan能取代mpls吗?—Vecloud
  4. HTC One 802w(联通双卡版本)刷机过程(只是记录大概的过程,网上已经有各步骤的详细过程)...
  5. 《面向模式的软件体系结构1--模式系统》读书笔记(5)--- 管理
  6. Linux 硬件信息命令
  7. 趣味编程:函数式链表的快速排序(参考答案)
  8. linux终端关闭时为什么会导致在其上启动的进程退出?
  9. 博士生找工作的真相!就问一声:你是否足够强大?
  10. 第 2 章 设计模式七大原则
  11. 《失败不是成功之母》阅读理解
  12. lisp 标注螺纹孔_尺寸标注之螺纹标注的正确方式
  13. 猫游记页游mysql_5款曾经极其火爆的页游,最后一款90后没听过80后才玩过
  14. Windows上查看MTU值和修改MTU的方法
  15. 第四届橙瓜网络文学奖20年十佳言情大神天下归元暂时排第三名
  16. 项目管理知识体系指南(十)项目风险管理
  17. vim配置参考备忘-------嵌入式
  18. 框架分析--框架驱动
  19. 笔记本突然没有WiFi了,网卡驱动带有感叹号,Intel(R) Wireless-AC 9462 #2 : 对本驱动程序而言,版本号错误。
  20. 为什么HikariCP是性能最好的数据库连接池?

热门文章

  1. 英语音标中KK音标、IPA音标、DJ音标各是什么意思
  2. SpringBoot+tomcat发布之war包发布
  3. 细胞穿膜肽TAT/血管肽Angiopep/靶向多肽cRGD偶联TIO2二氧化钛纳米粒(TiO2-Angiopep)
  4. 电子设计(4)高电平、低电平复位电路
  5. 机器学习这10年我们能在各自的领域做点什么?
  6. 2019年新个税计算方法
  7. NNDL实验实验六 卷积神经网络(4)ResNet18实现MNIST
  8. java较全的面试题
  9. steam for linux 安装目录,我该如何安装Steam?
  10. [DDC]Deep Domain Confusion: Maximizing for Domain Invariance