예제 #1
0
파일: bpr.py 프로젝트: crayonyon/BPR
import read_file as rf
import numpy as np
import computing as compute
import time


def get_predict_rui_ruj(uu, ii, jj):
    rui = np.dot(U[uu], V[ii]) + bi[ii]
    ruj = np.dot(U[uu], V[jj]) + bi[jj]
    return rui, ruj


train_records, yui, iu, i_te_u, u_test = rf.read_train_test()

n = 943
m = 1682
K = 5
d = 20

global_avg = 0.0
numerator = 0.0
denominator = 0.0
for u in range(n):
    for i in range(m):
        numerator += yui[u][i]
denominator = m * n
global_avg = float(numerator) / denominator

# initialization of model parameters
bi = np.zeros(m, dtype=float)
예제 #2
0
import read_file as rf
import computing as cp

data = rf.read_train_test()           # 从文件中读取 u1.base  u1.test  得到两个二维数组

train_data = data[0]
test_data = data[1]

# 计算 各个用户 的本身的所有打分的平均值  得到 aver_u_to_i 列表
aver_u_to_i = cp.compute_aver_u_to_i(train_data)

# 计算 两两用户 之间的 相似度 二维数组
cp.compute_Skj(train_data, aver_u_to_i)

예제 #3
0

def get_uu_i(uu, ii):
    i_set = {ii}
    iu_minus_i = list(set(iu[uu]) - i_set)
    uu_i = np.zeros(d, dtype=float)
    if len(iu_minus_i) <= 0:
        return iu_minus_i, uu_i
    for iii in iu_minus_i:
        uu_i = uu_i + W[iii]
    uu_i = uu_i / math.pow(len(iu_minus_i), alpha)
    return iu_minus_i, uu_i


# observed_records, yui, iu, i_te_u, u_test
observed_records, all_unobserved_records, yui, iu, i_te_u, u_test = rf.read_train_test(
)

n = 943
m = 1682
K = 5
d = 20

global_avg = 0.0
numerator = 0.0
denominator = 0.0

for u in range(n):
    for i in range(m):
        numerator += yui[u][i]
denominator = m * n
global_avg = float(numerator) / denominator
예제 #4
0
import numpy as np
import read_file as rf
import perform_evaluate as pe


# user_p_i, item_ped_u, i_te_u, u_test, yui
user_p_i, item_ped_u, i_te_u, u_test, yui = rf.read_train_test()

n = 943
m = 1682
K = 50

Swu = np.zeros((n, n), dtype=np.float)
max_swu = np.zeros(n, dtype=np.float)

# 计算相似度 Swu
for user_w in range(n):
    for user_u in range(n):
        iw = user_p_i[user_w]
        iu = user_p_i[user_u]

        numerator = len(list(set(iw) & set(iu)))
        denominator = len(list(set(iw) | set(iu)))

        if denominator != 0:
            Swu[user_w][user_u] = float(numerator) / denominator
        if max_swu[user_w] < Swu[user_w][user_u]:
            max_swu[user_w] = Swu[user_w][user_u]

# 正则化
for user_w in range(n):
예제 #5
0
파일: main.py 프로젝트: crayonyon/PopRank
import read_file as rf
import evaluation_etrics as ee
import numpy as np

ui_train_pairs, yui, Iu, I, U, ui_test_pair, I_te_u, U_test = rf.read_train_test(
)

n = 943
m = 1682
K = 5

global_avg = 0.0
numerator = 0.0
denominator = 0.0

for u in range(n):
    for i in range(m):
        numerator += yui[u][i]

denominator = n * m
global_avg = numerator / denominator

# recommendation list of items for user u   a dict  for every element, only have k items
# u from U_test
I_re_u = {}
for u in U_test:
    I_re_u[u] = []

# recommendation list of items for user u, for every element, have more than k items
I_re_u_mk = {}
for u in U_test: