学习笔记(十二):推荐系统-隐语义模型

#代码摘自唐宇迪《推荐系统》视频课程,数据集来自http://pan.baidu.com/s/1eS5VZ8Y中的“ml-1m"数据

from collections import deque
from six import next
import readers

import tensorflow as tf
import numpy as np

import time

np.random.seed(42)
u_num = 6040
i_num = 3952

batch_size = 1000
dims = 5
max_epochs = 50
place_device = "/cpu:0"

def get_data()
    df = readers.read_file("./ml-1m/ratings.dat",sep = "::")
    rows = len(df)
    df = df.iloc[np.random.permutation(rows)].reset_index(drop = True)
    split_index = int(rows*0.9)
    df_train = df[0:split_index]
    df_test = df[split_index:].reset_index(drop = True)
    return df_train,df_test

def clip(x):
    return np.clip(x, 1.0, 5.0)

def model(user_batch, item_batch, user_num, item_num, dim=5, device = "cpu:0"):
    with tf.device("/cpu:0"):
        with tf.variable_scope('lsi',reuse = True):
            bias_global = tf.get_variable("bias_global",shape=[])
            w_bias_user = tf.get_variable("embd_bias_user",shape=[user_num
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值