python - Lightfm : handling user and item cold-start

标签 python recommendation-engine matrix-factorization cold-start

我记得 lightfm 的优点之一是模型没有冷启动问题,用户和项目都冷启动:lightfm original paper

但是,我仍然不明白如何使用lightfm 来解决冷启动问题。我在 user-item interaction data 上训练了我的模型。据我了解,我只能对存在于我的数据集中的 profile_id 进行预测。

def predict(self, user_ids, item_ids, item_features=None,
            user_features=None, num_threads=1):
    """
    Compute the recommendation score for user-item pairs.

    Arguments
    ---------

    user_ids: integer or np.int32 array of shape [n_pairs,]
         single user id or an array containing the user ids for the
         user-item pairs for which a prediction is to be computed
    item_ids: np.int32 array of shape [n_pairs,]
         an array containing the item ids for the user-item pairs for which
         a prediction is to be computed.
    user_features: np.float32 csr_matrix of shape [n_users, n_user_features], optional
         Each row contains that user's weights over features.
    item_features: np.float32 csr_matrix of shape [n_items, n_item_features], optional
         Each row contains that item's weights over features.
    num_threads: int, optional
         Number of parallel computation threads to use. Should
         not be higher than the number of physical cores.

    Returns
    -------

    np.float32 array of shape [n_pairs,]
        Numpy array containing the recommendation scores for pairs defined
        by the inputs.
    """

    self._check_initialized()

    if not isinstance(user_ids, np.ndarray):
        user_ids = np.repeat(np.int32(user_ids), len(item_ids))

    assert len(user_ids) == len(item_ids)

    if user_ids.dtype != np.int32:
        user_ids = user_ids.astype(np.int32)
    if item_ids.dtype != np.int32:
        item_ids = item_ids.astype(np.int32)

    n_users = user_ids.max() + 1
    n_items = item_ids.max() + 1

    (user_features,
     item_features) = self._construct_feature_matrices(n_users,
                                                       n_items,
                                                       user_features,
                                                       item_features)

    lightfm_data = self._get_lightfm_data()

    predictions = np.empty(len(user_ids), dtype=np.float64)

    predict_lightfm(CSRMatrix(item_features),
                    CSRMatrix(user_features),
                    user_ids,
                    item_ids,
                    predictions,
                    lightfm_data,
                    num_threads)

    return predictions

任何有助于我理解的建议或指示都将不胜感激。谢谢

最佳答案

LightFM 与任何其他推荐算法一样,如果没有提供有关这些用户的额外信息,则无法对全新用户进行预测。尝试为新用户提出建议时的诀窍是根据算法在训练期间看到的特征来描述他们。

这可能最好用一个例子来解释。假设您的训练集中有 ID 介于 0 和 10 之间的用户,并且您想要对 ID 为 11 的新用户进行预测。如果您只有新用户的 ID,则算法将无法进行预测:毕竟,它对用户 11 的偏好是什么一无所知。然而,假设您有一些特征来描述用户:也许在注册过程中,每个用户都选择了他们的一些兴趣(例如,恐怖电影或浪漫喜剧)。如果这些特征在训练过程中出现,该算法可以了解平均而言哪些偏好与这些特征相关联,并且能够为任何可以使用相同特征描述的新用户生成推荐。在此示例中,如果您可以提供他们在注册过程中选择的偏好,您就可以对用户 11 进行预测。

在 LightFM 实现中,所有这些特征都将编码在特征矩阵中,可能采用单热编码的形式。在为用户 11 提供推荐时,您将为该用户构建一个新的特征矩阵:只要该特征矩阵仅包含训练期间出现的特征,您就可以进行预测。

请注意,具有仅对应于单个用户的特征通常很有用——例如“是用户 0”特征、“是用户 1”特征等等。对于新用户,这样的特征是无用的,因为训练中没有信息可供模型用来了解该特征。

关于python - Lightfm : handling user and item cold-start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46924119/

相关文章:

algorithm - 关于推荐系统的准确性

r - 在 R 中从 github 安装包时出错。dyn.load 中出错

hadoop - 我应该选择哪种开源推荐系统来处理大数据集

python - Dask优化中的ALS算法

python - scikit-learn - 我应该用 TF 还是 TF-IDF 拟合模型?

javascript - 使用 Django 进行视频聊天?或其他Python框架?

python - py2exe/pyinstaller 和 DispatchWithEvents

python - 在 numpy 数组中查找最大值行的最安全方法

python - 如何将 1D numpy 数组从 keras 层输出更改为图像(3D numpy 数组)

r - R 中线性回归线的 QR 分解(使用 qr.solve)