forked from recommenders-team/recommenders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_notebooks_python.py
141 lines (120 loc) · 5.78 KB
/
test_notebooks_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import pytest
import papermill as pm
from tests.notebooks_common import OUTPUT_NOTEBOOK, KERNEL_NAME
TOL = 0.05
ABS_TOL = 0.05
@pytest.mark.smoke
def test_sar_single_node_smoke(notebooks):
notebook_path = notebooks["sar_single_node"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(TOP_K=10, MOVIELENS_DATA_SIZE="100k"),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["map"] == pytest.approx(0.110591, rel=TOL, abs=ABS_TOL)
assert results["ndcg"] == pytest.approx(0.382461, rel=TOL, abs=ABS_TOL)
assert results["precision"] == pytest.approx(0.330753, rel=TOL, abs=ABS_TOL)
assert results["recall"] == pytest.approx(0.176385, rel=TOL, abs=ABS_TOL)
@pytest.mark.smoke
def test_baseline_deep_dive_smoke(notebooks):
notebook_path = notebooks["baseline_deep_dive"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(TOP_K=10, MOVIELENS_DATA_SIZE="100k"),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["rmse"] == pytest.approx(1.054252, rel=TOL, abs=ABS_TOL)
assert results["mae"] == pytest.approx(0.846033, rel=TOL, abs=ABS_TOL)
assert results["rsquared"] == pytest.approx(0.136435, rel=TOL, abs=ABS_TOL)
assert results["exp_var"] == pytest.approx(0.136446, rel=TOL, abs=ABS_TOL)
assert results["map"] == pytest.approx(0.052850, rel=TOL, abs=ABS_TOL)
assert results["ndcg"] == pytest.approx(0.248061, rel=TOL, abs=ABS_TOL)
assert results["precision"] == pytest.approx(0.223754, rel=TOL, abs=ABS_TOL)
assert results["recall"] == pytest.approx(0.108826, rel=TOL, abs=ABS_TOL)
@pytest.mark.smoke
def test_surprise_svd_smoke(notebooks):
notebook_path = notebooks["surprise_svd_deep_dive"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(MOVIELENS_DATA_SIZE="100k"),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["rmse"] == pytest.approx(0.96, rel=TOL, abs=ABS_TOL)
assert results["mae"] == pytest.approx(0.75, rel=TOL, abs=ABS_TOL)
assert results["rsquared"] == pytest.approx(0.29, rel=TOL, abs=ABS_TOL)
assert results["exp_var"] == pytest.approx(0.29, rel=TOL, abs=ABS_TOL)
assert results["map"] == pytest.approx(0.013, rel=TOL, abs=ABS_TOL)
assert results["ndcg"] == pytest.approx(0.1, rel=TOL, abs=ABS_TOL)
assert results["precision"] == pytest.approx(0.095, rel=TOL, abs=ABS_TOL)
assert results["recall"] == pytest.approx(0.032, rel=TOL, abs=ABS_TOL)
@pytest.mark.smoke
def test_vw_deep_dive_smoke(notebooks):
notebook_path = notebooks["vowpal_wabbit_deep_dive"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(MOVIELENS_DATA_SIZE="100k"),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["rmse"] == pytest.approx(0.985920, rel=TOL, abs=ABS_TOL)
assert results["mae"] == pytest.approx(0.71292, rel=TOL, abs=ABS_TOL)
assert results["rsquared"] == pytest.approx(0.231199, rel=TOL, abs=ABS_TOL)
assert results["exp_var"] == pytest.approx(0.231337, rel=TOL, abs=ABS_TOL)
assert results["map"] == pytest.approx(0.012535, rel=TOL, abs=ABS_TOL)
assert results["ndcg"] == pytest.approx(0.096594, rel=TOL, abs=ABS_TOL)
assert results["precision"] == pytest.approx(0.097770, rel=TOL, abs=ABS_TOL)
assert results["recall"] == pytest.approx(0.037612, rel=TOL, abs=ABS_TOL)
@pytest.mark.smoke
def test_lightgbm_quickstart_smoke(notebooks):
notebook_path = notebooks["lightgbm_quickstart"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(
MAX_LEAF=64,
MIN_DATA=20,
NUM_OF_TREES=100,
TREE_LEARNING_RATE=0.15,
EARLY_STOPPING_ROUNDS=20,
METRIC="auc",
),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["res_basic"]["auc"] == pytest.approx(0.7674, rel=TOL, abs=ABS_TOL)
assert results["res_basic"]["logloss"] == pytest.approx(
0.4669, rel=TOL, abs=ABS_TOL
)
assert results["res_optim"]["auc"] == pytest.approx(0.7757, rel=TOL, abs=ABS_TOL)
assert results["res_optim"]["logloss"] == pytest.approx(
0.4607, rel=TOL, abs=ABS_TOL
)
@pytest.mark.smoke
def test_cornac_bpr_smoke(notebooks):
notebook_path = notebooks["cornac_bpr_deep_dive"]
pm.execute_notebook(notebook_path, OUTPUT_NOTEBOOK, kernel_name=KERNEL_NAME)
pm.execute_notebook(
notebook_path,
OUTPUT_NOTEBOOK,
kernel_name=KERNEL_NAME,
parameters=dict(MOVIELENS_DATA_SIZE="100k"),
)
results = pm.read_notebook(OUTPUT_NOTEBOOK).dataframe.set_index("name")["value"]
assert results["map"] == pytest.approx(0.1091, rel=TOL, abs=ABS_TOL)
assert results["ndcg"] == pytest.approx(0.4034, rel=TOL, abs=ABS_TOL)
assert results["precision"] == pytest.approx(0.3550, rel=TOL, abs=ABS_TOL)
assert results["recall"] == pytest.approx(0.1802, rel=TOL, abs=ABS_TOL)