左眼永远见不到右眼,只能陪她一起哭泣。
NCF数据处理是对论文neural_collaborative_filtering作者所提出的神经网络协同过滤源代码的运行结果,不过在源代码的基础上做了一些更改,运行环境是 python3.6,keras1.2.2,tensorflow1.3.0 ,电脑本地运行约7个小时。
前言
GMF batch_size=256, dataset=’ml-1m’, epochs=100, learner=’adam’, lr=0.001, num_factors=8, num_neg=4, out=1, path=’Data/‘, regs=’[0,0]’, verbose=1
MLP batch_size=256, dataset=’ml-1m’, epochs=100, layers=’[64,32,16,8]’, learner=’adam’, lr=0.001, num_neg=4, out=1, path=’Data/‘, reg_layers=’[0,0,0,0]’, verbose=1
NeuMF batch_size=256, dataset=’ml-1m’, epochs=100, layers=’[64,32,16,8]’, learner=’adam’, lr=0.001, mf_pretrain=’’, mlp_pretrain=’’, num_factors=8, num_neg=4, out=1, path=’Data/‘, reg_layers=’[0,0,0,0]’, reg_mf=0, verbose=1
#user=6040, #item=3706, #train=994169, #test=6040
评估 leave-one-out
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
GMF = pd.read_table('GMF.txt',header=None, encoding='gb2312', sep=',')
MLP = pd.read_table('MLP.txt',header=None, encoding='gb2312', sep=',')
NeuMF = pd.read_table('NEUMF.txt',header=None, encoding='gb2312', sep=',')
GMF_HR = []
MLP_HR = []
NeuMF_HR = []
for i in GMF[0]:
GMF_HR.append(eval(i[-6:]))
for i in MLP[0]:
MLP_HR.append(eval(i[-6:]))
for i in NeuMF[0]:
NeuMF_HR.append(eval(i[-6:]))
GMF_NDGC= []
MLP_NDGC = []
NeuMF_NDGC = []
for i in GMF[1]:
GMF_NDGC.append(eval(i[-6:]))
for i in MLP[1]:
MLP_NDGC.append(eval(i[-6:]))
for i in NeuMF[1]:
NeuMF_NDGC.append(eval(i[-6:]))
GMF_loss= []
MLP_loss = []
NeuMF_loss = []
for i in GMF[2]:
GMF_loss.append(eval(i[-14:-8]))
for i in MLP[2]:
MLP_loss.append(eval(i[-14:-8]))
for i in NeuMF[2]:
NeuMF_loss.append(eval(i[-14:-8]))
f=plt.figure(figsize=(12,10))
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title("GMF-MLP-NeuMF HR 对比图",fontsize = 20)
plt.xlabel("Iteration",fontsize = 20)
plt.ylabel("HR",fontsize = 20)
plt.plot(range(100),GMF_HR,label = "GMF")#,linestyle='--')
plt.plot(range(100),MLP_HR,label = "MLP")#,linestyle='-.')
plt.plot(range(100),NeuMF_HR,label ="NeuMF")
plt.scatter(98,0.6437,marker='^',color = 'black')
plt.scatter(29,0.6763,marker='^',color = 'black')
plt.scatter(35,0.6848,marker='^',color = 'black')
plt.legend()
plt.grid(c="w")
plt.show()
f=plt.figure(figsize=(12,10))
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title("GMF-MLP-NeuMF NDGC 对比图",fontsize = 20)
plt.xlabel("Iteration",fontsize = 20)
plt.ylabel("NDGC",fontsize = 20)
plt.plot(range(100),GMF_NDGC,label = "GMF")
plt.plot(range(100),MLP_NDGC,label = "MLP")
plt.plot(range(100),NeuMF_NDGC,label ="NeuMF")
plt.scatter(98,0.3749,marker='^',color = 'black')
plt.scatter(29,0.3988,marker='^',color = 'black')
plt.scatter(35,0.4095,marker='^',color = 'black')
plt.legend()
plt.grid(c="w")
plt.show()
f=plt.figure(figsize=(12,10))
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title("GMF-MLP-NeuMF loss 对比图",fontsize = 20)
plt.xlabel("Iteration",fontsize = 20)
plt.ylabel("Loss",fontsize = 20)
plt.plot(range(100),GMF_loss,label = "GMF")
plt.plot(range(100),MLP_loss,label = "MLP")
plt.plot(range(100),NeuMF_loss,label ="NeuMF")
plt.legend()
plt.grid(c ="w")
plt.show()