lenskit.testing#
LensKit test harnesses and utilities.
This package contains utility code for testing LensKit and its components, including in derived packages. It relies on PyTest and Hypothesis.
Functions
|
Check if we have at least gb gigs of memory. |
|
Hypothesis strategy to generate valid integer user/item IDs. |
|
Set an environment variable & restore it. |
- lenskit.testing.scored_lists(*, n=integers(min_value=0, max_value=1000), scores=None)#
Hypothesis generator that produces scored lists.
- lenskit.testing.ml_100k()#
Fixture to load the MovieLens 100K dataset (currently as a data frame). It skips the test if the ML100K data is not available.
- Return type:
Generator[DataFrame, None, None]
- lenskit.testing.ml_ds(ml_ds_unchecked)#
Fixture to load the MovieLens test dataset. To use this, just include it as a parameter in your test:
def test_thing_with_data(ml_ds: Dataset): ...
Note
This is imported in
conftest.pyso it is always available in LensKit tests.
- lenskit.testing.ml_ds_unchecked()#
Fixture to load the MovieLens dataset, without checking for modifications.
Usually use
ml_ds()instead.
- lenskit.testing.ml_ratings()#
Fixture to load the test MovieLens ratings as a data frame. To use this, just include it as a parameter in your test:
def test_thing_with_data(ml_ratings: pd.DataFrame): ...
Note
This is imported in
conftest.pyso it is always available in LensKit tests.- Return type:
Generator[DataFrame, None, None]
- lenskit.testing.demo_recs()#
A demo set of train, test, and recommendation data.
- Return type:
- lenskit.testing.pop_recs()#
A demo set of train, test, and recommendation data, from most-popular.
- Return type:
- lenskit.testing.set_env_var(var, val)#
Set an environment variable & restore it.
- class lenskit.testing.DemoRecs(split, recommendations)#
Bases:
NamedTuple- Parameters:
split (TTSplit)
recommendations (ItemListCollection[UserIDKey])
- recommendations: ItemListCollection[UserIDKey]#
Alias for field number 1
- class lenskit.testing.ScorerTests#
Bases:
TrainingTestsCommon tests for scorer components. Many of these just test that the component runs, not that it produces correct output.
- expected_ndcg: ClassVar[float | tuple[float, float] | object | None] = None#
Asserts nDCG either greater than the provided expected value or between two values as tuple.
- expected_rmse: ClassVar[float | tuple[float, float] | object | None] = None#
Asserts RMSE either less than the provided expected value or between two values as tuple.
- test_score_empty_items(rng, ml_ds, trained_pipeline)#
score an empty list of items
- test_score_empty_query(rng, ml_ds, trained_pipeline)#
score with an empty query
- test_score_query_history(rng, ml_ds, trained_pipeline)#
score when query has user ID and history
- test_score_query_history_only(rng, ml_ds, trained_pipeline)#
score when query only has history
- test_score_unknown_item(rng, ml_ds, trained_pipeline)#
score with one target item unknown
- test_score_unknown_user(rng, ml_ds, trained_pipeline)#
score with an unknown user ID
- test_train_recommend(ml_ds)#
Test that a full train-recommend pipeline works.
- Parameters:
ml_ds (Dataset)
- test_train_score_items_missing_data(rng, ml_ds)#
train and score when some entities are missing data
- verify_models_equivalent(orig, copy)#
Verify that two models are equivalent.