model = ALS.train(training, rank, num_iterations, lambda)
# 使用验证集评估经过训练的模型
print "The model was trained with rank = %d, lambda = %.1f, and %d iterations.
\n" % \
(rank, lambda, num_iterations)
在详细日志记录模式下运行
train()
方法时要小心,此操作需要进行几次
RDD
投影和操作,因此可能会有长达几分钟的日志滚动。
模型一旦被创建,就使用均方根误差(
root mean squared error
,
RMSE
)来计算每个模型
的误差。
RMSE
是拥有实际评分的所有用户的
(
实际评分
-
预测评级
)
^2
的平均值的平
方根
。
5
我们的推荐程序也可以相应地实现
RMSE
计算:
def compute_rmse(model, data, n):
"""
计算RMSE,或 者 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.