环境信息:
Ubuntu 22.04--Python 3.9.12
Manjaro 5.15.60-1——Python 3.9.7
我正在使用"隐式"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-->(29238564(
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)
这个代码片段的最后一行是错误所在的地方;ValueError:行索引超出矩阵"的界限;在Ubuntu上运行,但在Manjaro上运行良好。正如你所看到的,当我调用model.user_factors.shape时,训练后的模型在Manjaro系统和Ubuntu系统上有不同的参数。这是一个矩阵的图像,它被提供给model.fit((调用,正如你所看到的,它看起来像是隐式的。它在两个系统上以不同的方式处理矩阵,并且似乎出于某种原因在Ubuntu中转换它。
有人能告诉我为什么会发生这种事吗?
看起来您使用了两个不同版本的隐式-API在v0.5.0中发生了变化https://github.com/benfred/implicit/releases/tag/v0.5.0,而model.fit现在需要一个user_plays-csr矩阵。你能在Manjaro版本上升级隐式的版本并重试吗?