lightfm.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:Movie-Recommendation-System 作者: turq84 项目源码 文件源码
def _process_sample_weight(self, interactions, sample_weight):

        if sample_weight is not None:

            if self.loss == 'warp-kos':
                raise NotImplementedError('k-OS loss with sample weights '
                                          'not implemented.')

            if not isinstance(sample_weight, sp.coo_matrix):
                raise ValueError('Sample_weight must be a COO matrix.')

            if sample_weight.shape != interactions.shape:
                raise ValueError('Sample weight and interactions '
                                 'matrices must be the same shape')

            if not (np.array_equal(interactions.row,
                                   sample_weight.row) and
                    np.array_equal(interactions.col,
                                   sample_weight.col)):
                raise ValueError('Sample weight and interaction matrix '
                                 'entries must be in the same order')

            if sample_weight.data.dtype != CYTHON_DTYPE:
                sample_weight_data = sample_weight.data.astype(CYTHON_DTYPE)
            else:
                sample_weight_data = sample_weight.data
        else:
            if np.array_equiv(interactions.data, 1.0):
                # Re-use interactions data if they are all
                # ones
                sample_weight_data = interactions.data
            else:
                # Otherwise allocate a new array of ones
                sample_weight_data = np.ones_like(interactions.data,
                                                  dtype=CYTHON_DTYPE)

        return sample_weight_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号