如何在此推荐系统中实施K折?

时间:2019-03-07 18:40:31

标签: keras recommendation-engine

任何人都知道如何在这种算法中实现k折,尝试一些方法但没有成功,有人可以帮助我吗?

from sklearn.model_selection import train_test_split
train, test = train_test_split(dataset, test_size=0.2)
n_users, n_movies = len(dataset.userId.unique()), len(dataset.movieId.unique())
n_latent_factors = 3

movie_input = keras.layers.Input(shape=[1],name='Item')
movie_embedding = keras.layers.Embedding(n_movies + 1, n_latent_factors, name='Movie-Embedding')(movie_input)
movie_vec = keras.layers.Conv1D(64,kernel_size=1)(movie_embedding)
movie_vec = keras.layers.MaxPooling1D(pool_size = (1))(movie_vec)
movie_vec = keras.layers.Flatten(name='FlattenMovies')(movie_vec)

user_input = keras.layers.Input(shape=[1],name='User')
user_embedding=(keras.layers.Embedding(n_users + 1, n_latent_factors,name='User-Embedding')(user_input))
user_vec = keras.layers.Conv1D(64,kernel_size=1)(user_embedding)
user_vec = keras.layers.MaxPooling1D(pool_size = (1))(user_vec)
user_vec = keras.layers.Flatten(name='FlattenUsers')(user_vec)

prod = keras.layers.dot([movie_vec, user_vec], axes=1,name='DotProduct')
model = keras.Model([user_input, movie_input], prod)
model.compile('adam', 'mean_squared_error')
history = model.fit([train.userId, train.movieId], train.rating, epochs=40) 

0 个答案:

没有答案