- 从dataframe中选择特征数据
ratings = ratings.map(lambda x: {
'movie_title':x['movie_title'],
'user_id':x['user_id']
})
movies = movies.map(lambda x: x['movie_title'])
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)
])