-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
58 lines (49 loc) · 1.69 KB
/
test.py
File metadata and controls
58 lines (49 loc) · 1.69 KB
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
from itertools import product
import numpy as np
from polynomial import PolynomialFeatures as CustomPolynomialFeatures
from sklearn.preprocessing import \
PolynomialFeatures as SklearnPolynomialFeatures
dtype_options = [np.float32, np.float64]
layout_options = [np.ascontiguousarray, np.asfortranarray]
n_features_options = [2, 5, 10]
degree_options = [1, 2, 5]
interaction_only_options = [True, False]
include_bias_options = [True, False]
order_options = ["C", "F"]
n_jobs_options = [1, 4, 8]
for settings in product(dtype_options,
n_features_options,
layout_options,
degree_options,
interaction_only_options,
include_bias_options,
order_options,
n_jobs_options):
dtype = settings[0]
n_features = settings[1]
layout = settings[2]
degree = settings[3]
interaction_only = settings[4]
include_bias = settings[5]
order = settings[6]
n_jobs = settings[7]
X = np.random.rand(2, n_features).astype(dtype)
X = layout(X)
custom_poly = CustomPolynomialFeatures(
degree,
interaction_only=interaction_only,
include_bias=interaction_only,
order=order,
n_jobs=n_jobs
)
sklearn_poly = SklearnPolynomialFeatures(
degree,
interaction_only=interaction_only,
include_bias=interaction_only,
order=order,
)
custom_poly = custom_poly.fit(X)
sklearn_poly = sklearn_poly.fit(X)
XP_custom = custom_poly.transform(X)
XP_sklearn = sklearn_poly.transform(X)
assert np.allclose(XP_custom, XP_sklearn), str(settings)