by wangben 2015.11
在工業界,邏輯迴歸是很常用的模型,一般大家在用邏輯迴歸做機器學習排序或者廣告預估時常用AUC來判斷排序的效果,邏輯迴歸是概率模型,除了排序的指標之外,有時會出現AUC比較好,但是概率擬合較差(很有可能是收斂的不好),在廣告GSP(Generalized second-price auction)競價模式中尤爲重要,所以我們還希望驗證模型對真實概率的擬合程度,這時就需要其他指標來衡量。
最常見的方式是MSE(Mean Square Error):
這個方式需要先收集一部分充分統計量的item,給出其統計CTR並且與模型給出的pCTR(predict ctr)進行比較,判斷擬合程度:
另一種選擇是使用NRIG(Normalized RelativeInformation Gain),NRIG是RIG的歸一化版本。
給定一個測試集M,整個數據集的統計CTR可以定義爲:
其中ym是真實label,取值爲0或者1
那麼數據整體熵的定義就是:
對於模型預測結果,我們可以給出其交叉熵cross entropy(Loss Function):
其中pm指的是模型對第m個樣本所預測的概率。
從而模型能夠得到的相對信息增益定義如下:
從公式可以看出,如果增益越大,說明收斂的越好,模型質量應該越高
如果我們對每一個樣本的預測概率相對於整體CTR做歸一化,就可以得到相應的NRIG,歸一化的預測概率如下:
python測試代碼如下:
#!/usr/bin/python
#by [email protected] 20151020 NRIG SCORE,big is better,infomation gain is bigger
import sys
import math
#
def entropy(p):
return -( p * math.log(p,2) + (1 - p) * math.log(1 - p,2) )
def crossEntropy( label, p ):
return -( label * math.log(p,2) + (1 - label) * math.log(1 - p,2) )
if __name__ == "__main__":
listScore = []
sum = 0.0
test_size = 0.0
ce_sum = 0.0
avg_pre = 0.0
#input format:
#label\tpredictScore
for line in open(sys.argv[1]):
line = line.rstrip()
listLine = line.split()
if len(listLine) != 2:
continue
label = float(listLine[0])
value = float(listLine[1])
test_size += 1.0
if label > 0:
sum += label
ce_sum += crossEntropy( label , value)
#print "debug :",ce_sum
avg_pre += value
listScore.append([label,value])
print "empirical CTR(avg CTR): ",sum,test_size,sum/test_size
avg_p = sum/test_size
Hp = entropy(avg_p)
print "entropy: ",Hp
ce = ce_sum/test_size
print "cross entropy: ",ce_sum,test_size,ce
print "RIG: ",(Hp-ce)/Hp
#NRIG
n_ce = 0.0
avg_pre /= test_size
print "average prediction: ",avg_pre
diff_rate = avg_p/avg_pre
for item in listScore:
n_ce += crossEntropy( item[0] , item[1]*diff_rate )
n_ce /= test_size
print "normalized ce: ",n_ce
print "NRIG: ",(Hp-n_ce)/Hp
reference:
Click-through Prediction for Advertising in Twitter Timeline. kdd2015