建模零碎知识点
作者:互联网
- 从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)
])
标签:知识点,vocabulary,keras,movie,建模,零碎,user,tf,id 来源: https://blog.csdn.net/qq_43283527/article/details/122774135