|
13 | 13 | from pytest import approx, fixture, mark
|
14 | 14 |
|
15 | 15 | from lenskit.basic import BiasScorer, PopScorer
|
16 |
| -from lenskit.batch import BatchPipelineRunner, predict, recommend |
| 16 | +from lenskit.batch import BatchPipelineRunner, predict, recommend, score |
17 | 17 | from lenskit.data import Dataset, ItemList, UserIDKey, from_interactions_df
|
18 | 18 | from lenskit.data.convert import normalize_interactions_df
|
19 | 19 | from lenskit.metrics import NDCG, RBP, RMSE, RunAnalysis
|
@@ -64,6 +64,21 @@ def test_predict_single(mlb: MLB):
|
64 | 64 | assert preds >= 1 and preds <= 5
|
65 | 65 |
|
66 | 66 |
|
| 67 | +def test_score_single(mlb: MLB): |
| 68 | + res = score(mlb.pipeline, {1: ItemList([31])}, n_jobs=1) |
| 69 | + |
| 70 | + assert len(res) == 1 |
| 71 | + uid, result = next(iter(res)) |
| 72 | + assert isinstance(uid, UserIDKey) |
| 73 | + assert uid.user_id == 1 |
| 74 | + assert len(result) == 1 |
| 75 | + assert result.ids()[0] == 31 |
| 76 | + |
| 77 | + preds = result.field("score") |
| 78 | + assert preds is not None |
| 79 | + assert preds >= 1 and preds <= 5 |
| 80 | + |
| 81 | + |
67 | 82 | def test_recommend_user(mlb: MLB):
|
68 | 83 | user = 5
|
69 | 84 |
|
|
0 commit comments