PRank算法python实现
来源:互联网 发布:送餐员下载什么软件 编辑:程序博客网 时间:2024/06/05 23:44
算法流程
python实现
数据集:LETOR4.0
import numpy as nptrain=[]label=[]#读取文件for line in open("train.txt"): lines=line.split(' ') label.append([float(lines[0])+1,lines[1]]) data=[] for i in range(2,48): data.append(float(lines[i].split(':')[1])) train.append(data)train = np.matrix(train)label = np.matrix(label)#预测def predict(w_x, b, k): for i in range(1,k): if b[i] > w_x: return isamples, features = train.shapeclassify =3w = np.matrix(np.zeros(features))b = np.zeros(classify+1)b[classify] = np.inf#迭代次数for _ in range(100): print 'iterator:',_ for i in range(samples): x = train[i] w_x = (w * x.T)[0, 0] p_label = predict(w_x, b, classify+1) r = np.zeros(classify) y = np.zeros(classify) p_true=float(label[i,0]) if p_label != p_true: for j in range(1,classify): if p_true <= j: y[j] = -1 else: y[j] = 1 for j in range(1,classify): if (w_x - b[j]) * y[j] <= 0: r[j] = y[j] else: r[j] = 0 #参数更新(更新率) #w = w + 0.1*np.sum(r) * x w = w + np.sum(r) * x for j in range(1,classify): b[j] = b[j] - r[j]count=0for i in range(samples): x = train[i] w_x = (w * x.T)[0, 0] p_label = predict(w_x, b, classify+1) if float(label[i,0])==p_label: count=count+1 # print(label[i,0], p_label)print count,samples,count*1.0/samples
评价指标
IR的评价指标-MAP,NDCG和MRR
待更新
0 0
- PRank算法python实现
- Learning to Rank中Pointwise关于PRank算法源码实现
- 【学习排序】 Learning to Rank中Pointwise关于PRank算法源码实现
- 主动排序学习算法之PRank
- 排序算法python实现
- python radix算法实现
- Python 实现Apriori算法
- Python 实现 Prim算法
- bellman_ford算法 python实现
- python实现递归算法
- Python实现KNN算法
- Python实现KMP算法
- 遗传算法Python实现
- KNN算法Python实现
- BFPRT算法Python实现
- Python实现决策树算法
- python实现knn算法
- Python 实现递归算法
- React基础知识一
- 微信开发之——接口返回码
- runtime源码探究(四)区分isKindOfClass、isSubclassOfClass、isMemberOfClass
- chrome livestyle插件
- 189. Rotate Array \ 169. Majority Element \ Best time to buy
- PRank算法python实现
- 清除浮动的几种方法
- 隐藏文字
- Spring 4 注解新特性
- git笔记 常规使用
- android音量键调节听筒音量的大小
- 定时器、Date
- FIS
- 为什么不喜欢用360浏览器开发