【发布时间】:2018-05-17 12:34:41
【问题描述】:
当我发现 ALS 中的因子矩阵首先随机初始化时,需要创建一点 Pyspark ALS 推荐系统的集合,因此不同的运行会给出稍微不同的结果,使用它们的平均值会得到更准确的结果。所以我训练模型 2 次 --> 它给了我不同的模型 ALS 对象,但是当使用 recommendForAllUsers() 方法时,不同的模型给出了相同的推荐输出。这里有什么问题,为什么需要重新启动脚本来获得不同的输出,即使有不同的预测 ALS 模型?
P.S没有伪随机的种子参数。
def __train_model(ratings):
"""Train the ALS model with the current dataset
"""
logger.info("Training the ALS model...")
als = ALS(rank=rank, maxIter=iterations, implicitPrefs=True, regParam=regularization_parameter,
userCol="order_id", itemCol="product_id", ratingCol="count")
model = als.fit(ratings)
logger.info("ALS model built!")
return model
model1 = __train_model(ratings_DF)
print(model1)
sim_table_1 = model1.recommendForAllUsers(100).toPandas()
model2 = __train_model(ratings_DF)
print(model2)
sim_table_2 = model2.recommendForAllUsers(100).toPandas()
print('Equality of objects:', model1 == model2)
输出:
INFO:__main__:Training the ALS model...
INFO:__main__:ALS model built!
ALS_444a9e62eb6938248b4c
INFO:__main__:Training the ALS model...
INFO:__main__:ALS model built!
ALS_465c95728272696c6c67
Equality of objects: False
【问题讨论】:
标签: python-3.x pyspark recommendation-engine