Professional Documents
Culture Documents
non-negative-matrix-factorization
non-negative-matrix-factorization
non-negative-matrix-factorization
algo = NMF()
algo.fit(trainset)
predictions = algo.test(testset)
accuracy.rmse(predictions, verbose=True)
def load_model(filename):
"""Tải mô hình đã huấn luyện từ tệp."""
with open(filename, 'rb') as file:
model = pickle.load(file)
return model
1
1.1 Tạo gợi ý cho người dùng
[4]: def generate_recommendations(user_id, algo, df):
"""Tạo và in ra 10 gợi ý phim hàng đầu cho một người dùng."""
reader = Reader(rating_scale=(0.5, 5))
data = Dataset.load_from_df(df[['userId', 'id', 'rating']], reader)
trainset = data.build_full_trainset()
testset = trainset.build_anti_testset()
predictions = algo.test(testset)
NMF
10 gợi ý hàng đầu cho người dùng 1:
2
Tên phim: Elizabeth, Xếp hạng ước tính: 4.19
Tên phim: The Story of a Cheat, Xếp hạng ước tính: 4.06
Tên phim: Malcolm X, Xếp hạng ước tính: 4.04
Tên phim: Birdman of Alcatraz, Xếp hạng ước tính: 3.98
Tên phim: Crank, Xếp hạng ước tính: 3.98
Tên phim: Frankenstein, Xếp hạng ước tính: 3.96
Tên phim: Rio Bravo, Xếp hạng ước tính: 3.93
Tên phim: House of Cards, Xếp hạng ước tính: 3.92
Tên phim: The Lord of the Rings, Xếp hạng ước tính: 3.85
Tên phim: The Ring, Xếp hạng ước tính: 3.83