0
点赞
收藏
分享

微信扫一扫

建模零碎知识点

思考的鸿毛 2022-02-03 阅读 39
  1. 从dataframe中选择特征数据
# select the basic features
ratings = ratings.map(lambda x: {
	'movie_title':x['movie_title'],
	'user_id':x['user_id']
})
movies = movies.map(lambda x: x['movie_title'])

# 构建词汇表,将用户id和电影标题转换为嵌入层的整数索引
user_ids_vocabulary = tf.keras.layers.StringLookup(mask_token = None)
user_ids_vocabulary.adapt(ratings.map(lambda x :x['user_id']))

movie_titles_vocabulary = tf.keras.layers.StringLookup(mask_token =None)
movie_titles_vocabulary.adapt(movies)

# 定义用户和电影各自的模型:
user_model = tf.keras.Sequential([
	user_ids_vocabulary,
	tf.keras.layers.Embedding(user_ids_vocabulary.vocab_size(),64)
])

movie_model = tf.keras.Sequential([
	movie_titles_vocabulary,
	tf.keras.layers.Embedding(movie_titles_vocabulary.vocb_size(),64)
])
举报

相关推荐

0 条评论