-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: cross validate timings #233
base: main
Are you sure you want to change the base?
Changes from 6 commits
2b95c08
e474430
b05fbe1
a64db58
85c1604
5afc0e4
ce5f1c0
46e05c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,5 +371,247 @@ def test_happy_path_with_intersection( | |
], | ||
"metrics": expected_metrics, | ||
} | ||
assert actual == expected | ||
|
||
@pytest.mark.parametrize( | ||
"ref_models,validate_ref_models,expected_metrics,compute_timings", | ||
( | ||
( | ||
["popular"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep only ["popular"] and not put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
False, | ||
[ | ||
{ | ||
"model": "random", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.0, | ||
"intersection_popular": 0.5, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.5, | ||
"intersection_popular": 0.75, | ||
"fit_time": 0.0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's drop timings from expected dicts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"recommend_time": 0.0, | ||
}, | ||
], | ||
True, | ||
), | ||
( | ||
["popular"], | ||
True, | ||
[ | ||
{ | ||
"model": "popular", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.5, | ||
"intersection_popular": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.0, | ||
"intersection_popular": 0.5, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "popular", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.25, | ||
"intersection_popular": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.5, | ||
"intersection_popular": 0.75, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
], | ||
True, | ||
), | ||
( | ||
["random"], | ||
False, | ||
[ | ||
{ | ||
"model": "popular", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.5, | ||
"intersection_random": 0.5, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "popular", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.25, | ||
"intersection_random": 0.75, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
], | ||
True, | ||
), | ||
( | ||
["random"], | ||
True, | ||
[ | ||
{ | ||
"model": "popular", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.5, | ||
"intersection_random": 0.5, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.0, | ||
"intersection_random": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "popular", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.25, | ||
"intersection_random": 0.75, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.5, | ||
"intersection_random": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
], | ||
True, | ||
), | ||
(["random", "popular"], False, [], True), | ||
( | ||
["random", "popular"], | ||
True, | ||
[ | ||
{ | ||
"model": "popular", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.5, | ||
"intersection_random": 0.5, | ||
"intersection_popular": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 0, | ||
"precision@2": 0.5, | ||
"recall@1": 0.0, | ||
"intersection_random": 1.0, | ||
"intersection_popular": 0.5, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "popular", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.25, | ||
"intersection_random": 0.75, | ||
"intersection_popular": 1.0, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
{ | ||
"model": "random", | ||
"i_split": 1, | ||
"precision@2": 0.375, | ||
"recall@1": 0.5, | ||
"intersection_random": 1.0, | ||
"intersection_popular": 0.75, | ||
"fit_time": 0.0, | ||
"recommend_time": 0.0, | ||
}, | ||
], | ||
True, | ||
), | ||
), | ||
) | ||
def test_happy_path_with_intersection_timings( | ||
self, | ||
ref_models: tp.Optional[tp.List[str]], | ||
validate_ref_models: bool, | ||
expected_metrics: tp.List[tp.Dict[str, tp.Any]], | ||
compute_timings: bool, | ||
) -> None: | ||
splitter = LastNSplitter(n=1, n_splits=2, filter_cold_items=False, filter_already_seen=False) | ||
|
||
actual = cross_validate( | ||
dataset=self.dataset, | ||
splitter=splitter, | ||
metrics=self.metrics_intersection, | ||
models=self.models, | ||
k=2, | ||
filter_viewed=False, | ||
ref_models=ref_models, | ||
validate_ref_models=validate_ref_models, | ||
compute_timings=compute_timings, | ||
) | ||
|
||
time_threshold = 0.5 | ||
|
||
for data in actual["metrics"]: | ||
print(data["fit_time"]) | ||
print(data["recommend_time"]) | ||
assert data["fit_time"] < time_threshold | ||
assert data["recommend_time"] < time_threshold | ||
|
||
expected = { | ||
"splits": [ | ||
{ | ||
"i_split": 0, | ||
"test": 2, | ||
"test_items": 2, | ||
"test_users": 2, | ||
"train": 2, | ||
"train_items": 2, | ||
"train_users": 2, | ||
}, | ||
{ | ||
"i_split": 1, | ||
"test": 4, | ||
"test_items": 3, | ||
"test_users": 4, | ||
"train": 6, | ||
"train_items": 2, | ||
"train_users": 4, | ||
}, | ||
], | ||
"metrics": expected_metrics, | ||
} | ||
assert actual == expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we needed to round not in the actual code but in the tests below. we are adding rounding just to pass the tests. so it shouldn't affect the actual code in framework.
let's round to 5 digits here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done