LTR-pointwise之prank-python代码实现

6,187次阅读
没有评论

共计 862 个字符,预计需要花费 3 分钟才能阅读完成。

LTR-pointwise之prank-python代码实现

修改记录:

2017/3/22修改代码中的部分BUG
核心代码 https://github.com/zhusimaji/ml/blob/master/prank.py

def learn_to_rank(self):
    print 'start to learn rank'
    new_label = [0 for x in range(self.rank_label)]
    tao = []

    self.weight = [0.0 for x in range(self.rank_cate)]
    for num in range(self.rank_iter):
        for i in tqdm(range(self.rank_num)):
            predict_rank = 0
            sumwx = sum([self.weight[x] * self.source_data[i][x + 2]
                         for x in range(len(self.weight))])

            # 预测排名
            for r in range(self.rank_label):
                if sumwx - self.br[r] < 0:
                    predict_rank = r
                    break
            # 获取真实label
            if self.source_data[i][0] != predict_rank:
                for r in range(self.rank_label):
                    if self.source_data[i][0] - r < 0:
                        new_label[r] = -1
                    else:
                        new_label[r] = 1

            tao = [new_label[x] if (
                sumwx - self.br[x]) * new_label[x] <= 0 else 0.0 for x in range(self.rank_label)]
            tao_sum = sum(tao)
            new_weight = [self.weight[x] + tao_sum * self.source_data[i][x+2]
                          for x in range(self.rank_cate)]
            self.weight = new_weight
            for  r in  range(self.rank_label):
                self.br[r] = self.br[r] - tao[r]
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2018-03-21发表,共计862字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码