【发布时间】:2022-09-30 05:23:39
【问题描述】:
环境信息:
Ubuntu 22.04——Python 3.9.12
Manjaro 5.15.60-1——Python 3.9.7
我正在使用 \'implicit\' python 包开发一个隐式推荐模型。我最近在我的 Manjaro 文件系统上遇到了一些依赖问题。所以当我弄清楚这一点时,我决定启动到我的 Ubuntu 22.04 分区并在那里工作。不幸的是,我在 Manjaro 上工作的代码在 Ubuntu 上没有产生预期的结果。因此,作为一种故障排除方法,我继续使用隐式包 lastfm 推荐教程 (https://benfred.github.io/implicit/tutorial_lastfm.html) 创建一个新笔记本,以排除任何明显的用户错误。
\'\'\'
from implicit.datasets.lastfm import get_lastfm
artists, users, artist_user_plays = get_lastfm()
from implicit.nearest_neighbours import bm25_weight
# weight the matrix, both to reduce impact of users that have played the same artist thousands of times
# and to reduce the weight given to popular items
artist_user_plays = bm25_weight(artist_user_plays, K1=100, B=0.8)
# get the transpose since the most of the functions in implicit expect (user, item) sparse matrices instead of (item, user)
user_plays = artist_user_plays.T.tocsr()
from implicit.als import AlternatingLeastSquares
model = AlternatingLeastSquares(factors=64, regularization=0.05)
model.fit(user_plays)
model.user_factors.shape
输出 Manjaro-->(358867,64)
输出 Ubuntu-->(292385, 64)
import pandas as pd
userid=max(pd.DataFrame.sparse.from_spmatrix(user_plays).index)
ids, scores = model.recommend(userid, user_plays[userid], N=10, filter_already_liked_items=False)
这段代码 sn-p 的最后一行是错误所在。它在 Ubuntu 上吐出“ValueError: row index out of bounds for matrix”,但在 Manjaro 上运行良好。正如您在我调用 model.user_factors.shape 时看到的那样,训练后的模型在 Manjaro 系统和 Ubuntu 系统上具有不同的参数。这是一个矩阵的image,它被提供给 model.fit() 调用,正如你所看到的,它看起来隐式在两个系统上以不同的方式处理矩阵,并且似乎出于某种原因在 Ubuntu 中对其进行了转换.
谁能告诉我为什么会发生这种情况?
-
与 Manjaro 相比,您在 Ubuntu 上的 python 版本是什么????
-
哎呀...问题已更新为 OS 和 Python 版本。
-
这两个隐式软件包之间是否存在主要发行版本差异?
-
不,它们都是版本 \'0.5.2\'
标签: python ubuntu recommendation-engine manjaro