本文整理汇总了Python中lightfm.lightfm.LightFM.get_item_representations方法的典型用法代码示例。如果您正苦于以下问题:Python LightFM.get_item_representations方法的具体用法?Python LightFM.get_item_representations怎么用?Python LightFM.get_item_representations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lightfm.lightfm.LightFM
的用法示例。
在下文中一共展示了LightFM.get_item_representations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_predict_not_fitted
# 需要导入模块: from lightfm.lightfm import LightFM [as 别名]
# 或者: from lightfm.lightfm.LightFM import get_item_representations [as 别名]
def test_predict_not_fitted():
model = LightFM()
with pytest.raises(ValueError):
model.predict(np.arange(10), np.arange(10))
with pytest.raises(ValueError):
model.predict_rank(1)
with pytest.raises(ValueError):
model.get_user_representations()
with pytest.raises(ValueError):
model.get_item_representations()
示例2: test_get_representations
# 需要导入模块: from lightfm.lightfm import LightFM [as 别名]
# 或者: from lightfm.lightfm.LightFM import get_item_representations [as 别名]
def test_get_representations():
model = LightFM(random_state=SEED)
model.fit_partial(train, epochs=10)
num_users, num_items = train.shape
for (item_features, user_features) in (
(None, None),
(
(sp.identity(num_items) + sp.random(num_items, num_items)),
(sp.identity(num_users) + sp.random(num_users, num_users)),
),
):
test_predictions = model.predict(
test.row, test.col, user_features=user_features, item_features=item_features
)
item_biases, item_latent = model.get_item_representations(item_features)
user_biases, user_latent = model.get_user_representations(user_features)
assert item_latent.dtype == np.float32
assert user_latent.dtype == np.float32
predictions = (
(user_latent[test.row] * item_latent[test.col]).sum(axis=1)
+ user_biases[test.row]
+ item_biases[test.col]
)
assert np.allclose(test_predictions, predictions, atol=0.000001)