1、隐语义模型:
物品:表示为长度为k的向量q(每个分量都表示 物品具有某个特征的程度)
用户兴趣:表示为长度为k的向量p(每个分量都表示 用户对某个特征的喜好程度)
用户u对物品i的兴趣可以表示为:
其损失函数定义为:
使用随机梯度下降,获得参数p,q。
负样本生成:对于只有正反馈信息(用户收藏了,关注了xxx)的数据集,需要生成负样本,原则如下
1)生成的负样本要和正样本数量相当
2)物品越热门(用户没有收藏该物品),越有可能是负样本
2、数据集:https://grouplens.org/datasets/movielens/
格式:
3、参考代码:
# -*- coding: utf-8 -*-
'''
Created on 2017年9月15日
@author: Jason.F
'''
from math import exp
import pandas as pd
import numpy as np
import pickle
import time
from numpy import rank
def getUserNegativeItem(frame, userID):
'''
获取用户负反馈物品:热门但是用户没有进行过评分 与正反馈数量相等
:param frame: ratings数据
:param userID:用户ID
:return: 负反馈物品
'''
userItemlist = list(set(frame[frame['userid'] == userID]['itemid'])) #用户评分过的物品
otherItemList = [item for item in set(frame['itemid'].values) if item not in userItemlist] #用户没有评分的物品
itemCount = [len(frame[frame['itemid'] == item]['userid']) for item in otherItemList] #物品热门程度
series = pd.Series(itemCount, index=otherItemList)
series = series.sort_values(ascending=False)[:len(userItemlist)] #获取正反馈物品数量的负反馈物品