python - LightFM推荐: Inconsistent error with interaction data

标签 python machine-learning collaborative-filtering recommendation-engine

我有以下带有 LightFM 推荐模块的基本代码:

# Interactions
A=[0,1,2,3,4,4] # users
B=[0,0,1,2,2,3] # items
C=[1,1,1,1,1,1] # weights
matrix = sparse.coo_matrix((C,(A,B)),shape=(max(A)+1,max(B)+1))
# Create model
model = LightFM(loss='warp')
# Train model
model.fit(matrix, epochs=30)
# Predict
scores = model.predict(1, np.array([0,1,2,3]))
print(scores)

这将返回以下错误:

> C:\Program
> Files\Python\Python36\lib\site-packages\numpy\core\_methods.py:32:
> RuntimeWarning: invalid value encountered in reduce   return
> umr_sum(a, axis, dtype, out, keepdims) Traceback (most recent call
> last):   File "run.py", line 15, in <module>
>     model.fit(matrix, epochs=100)   File "C:\Program Files\Python\Python36\lib\site-packages\lightfm\lightfm.py", line 476,
> in fit
>     verbose=verbose)   File "C:\Program Files\Python\Python36\lib\site-packages\lightfm\lightfm.py", line 580,
> in fit_partial
>     self._check_finite()   File "C:\Program Files\Python\Python36\lib\site-packages\lightfm\lightfm.py", line 410,
> in _check_finite
>     raise ValueError("Not all estimated parameters are finite," ValueError: Not all estimated parameters are finite, your model may
> have diverged. Try decreasing the learning rate or normalising feature
> values and sample weights

奇怪的是,对交互数据进行一些更改即可使其正常工作,如下所示:

# Interactions
A=[0,1,2,3,4,4]
B=[0,0,1,2,2,10] # notice the 10 here
C=[1,1,1,1,1,1]

有人可以帮我吗?

最佳答案

#Predict
scores = model.predict(1, np.array([0,1,2,3]))
print(scores)

[-0.17697991 -0.55117112 -0.37800685 -0.57664376]

它对我来说工作正常,更新 lightFM 版本吗?

关于python - LightFM推荐: Inconsistent error with interaction data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50307866/

相关文章:

machine-learning - Keras:内核和事件正则化器之间的区别

scala - 如何在协同过滤中设置 ALS 隐式反馈的首选项?

python - 为什么在文本模式下编辑时不应该使用 os.linesep?

python BeautifulSoup解析表

machine-learning - SVM 的替代方案

machine-learning - 先验分布在分类中重要吗?

similarity - 为什么 LogLikelihoodSimilarity 函数对于 0 和 1 的数据集返回大于 1.0 的值?

apache-spark - Spark MLlib - 使用隐式反馈训练协同过滤 - 奇怪的警告

python - 压平numpy数组

python - 如何实现装饰生成器