text_plain_output_1.png
from tensorflow.keras.layers import Input, Embedding, Dot, Flatten, Dense, Dropout

from tensorflow.keras.models import Model

import numpy as np

import numpy as np

import pandas as pd

import pandas as pd

data = pd.read_csv('/kaggle/input/flicktime/rating.csv')

import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input, Embedding, Dot, Flatten, Dense, Dropout
from tensorflow.keras.models import Model
n_users = data.userId.nunique()
n_movies = data.movieId.nunique()
user_ids = data.userId.astype('category').cat.codes.values
movie_ids = data.movieId.astype('category').cat.codes.values
ratings = data.rating.values
user_item_matrix = np.zeros((n_users, n_movies))
for i in range(len(ratings)):
    user_item_matrix[user_ids[i], movie_ids[i]] = ratings[i]
embedding_size = 64
user_input = Input(shape=(1,))
user_embed = Embedding(n_users, embedding_size)(user_input)
user_embed = Flatten()(user_embed)
movie_input = Input(shape=(1,))
movie_embed = Embedding(n_movies, embedding_size)(movie_input)
movie_embed = Flatten()(movie_embed)
dot_product = Dot(axes=1)([user_embed, movie_embed])
dense1 = Dense(64, activation='relu')(dot_product)
dropout1 = Dropout(0.2)(dense1)
dense2 = Dense(32, activation='relu')(dropout1)
dropout2 = Dropout(0.2)(dense2)
output = Dense(1)(dropout2)
model = Model(inputs=[user_input, movie_input], outputs=output)
model.compile(loss='mse', optimizer='adam')

user_ids_test = np.random.choice(n_users, 10)
movie_ids_test = np.random.choice(n_movies, 10)

predictions = model.predict([user_ids_test, movie_ids_test]).flatten()
print(predictions)