forked from pycaret/pycaret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_classification_engines.py
162 lines (130 loc) · 4.71 KB
/
test_classification_engines.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import daal4py
import sklearn
import pycaret.classification
import pycaret.datasets
def test_engines_setup_global_args():
"""Tests the setting of engines using global arguments in setup."""
juice_dataframe = pycaret.datasets.get_data("juice")
exp = pycaret.classification.ClassificationExperiment()
# init setup
exp.setup(
juice_dataframe,
target="Purchase",
remove_multicollinearity=True,
multicollinearity_threshold=0.95,
log_experiment=True,
html=False,
session_id=123,
n_jobs=1,
engine={"lr": "sklearnex"},
)
# Default Model Engine ----
assert exp.get_engine("lr") == "sklearnex"
model = exp.create_model("lr")
assert isinstance(
model, daal4py.sklearn.linear_model.logistic_path.LogisticRegression
)
def test_engines_global_methods():
"""Tests the setting of engines using methods like set_engine (global changes)."""
juice_dataframe = pycaret.datasets.get_data("juice")
exp = pycaret.classification.ClassificationExperiment()
# init setup
exp.setup(
juice_dataframe,
target="Purchase",
remove_multicollinearity=True,
multicollinearity_threshold=0.95,
log_experiment=True,
html=False,
session_id=123,
n_jobs=1,
engine={"lr": "sklearnex"},
)
assert exp.get_engine("lr") == "sklearnex"
# Globally reset engine ----
exp._set_engine("lr", "sklearn")
assert exp.get_engine("lr") == "sklearn"
model = exp.create_model("lr")
assert isinstance(model, sklearn.linear_model._logistic.LogisticRegression)
def test_create_model_engines_local_args():
"""Tests the setting of engines for create_model using local args."""
juice_dataframe = pycaret.datasets.get_data("juice")
exp = pycaret.classification.ClassificationExperiment()
# init setup
exp.setup(
juice_dataframe,
target="Purchase",
remove_multicollinearity=True,
multicollinearity_threshold=0.95,
log_experiment=True,
html=False,
session_id=123,
n_jobs=1,
)
# Default Model Engine ----
assert exp.get_engine("lr") == "sklearn"
model = exp.create_model("lr")
assert isinstance(model, sklearn.linear_model._logistic.LogisticRegression)
# Override model engine locally ----
model = exp.create_model("lr", engine="sklearnex")
assert isinstance(
model, daal4py.sklearn.linear_model.logistic_path.LogisticRegression
)
# Original engine should remain the same
assert exp.get_engine("lr") == "sklearn"
def test_compare_models_engines_local_args():
"""Tests the setting of engines for compare_models using local args."""
juice_dataframe = pycaret.datasets.get_data("juice")
exp = pycaret.classification.ClassificationExperiment()
# init setup
exp.setup(
juice_dataframe,
target="Purchase",
remove_multicollinearity=True,
multicollinearity_threshold=0.95,
log_experiment=True,
html=False,
session_id=123,
n_jobs=1,
)
# Default Model Engine ----
assert exp.get_engine("lr") == "sklearn"
model = exp.compare_models(include=["lr"])
assert isinstance(model, sklearn.linear_model._logistic.LogisticRegression)
# Original engine should remain the same
assert exp.get_engine("lr") == "sklearn"
# Override model engine locally ----
model = exp.compare_models(include=["lr"], engine={"lr": "sklearnex"})
assert isinstance(
model, daal4py.sklearn.linear_model.logistic_path.LogisticRegression
)
# Original engine should remain the same
assert exp.get_engine("lr") == "sklearn"
model = exp.compare_models(include=["lr"])
assert isinstance(model, sklearn.linear_model._logistic.LogisticRegression)
def test_all_sklearnex_models():
ALGORITHMS_LIST = ["lr", "knn", "rbfsvm"]
juice_dataframe = pycaret.datasets.get_data("juice")
exp = pycaret.classification.ClassificationExperiment()
# init setup
exp.setup(
juice_dataframe,
target="Purchase",
remove_multicollinearity=True,
multicollinearity_threshold=0.95,
log_experiment=True,
html=False,
session_id=123,
n_jobs=1,
)
for algo in ALGORITHMS_LIST:
model = exp.create_model(algo)
parent_library = model.__module__
assert parent_library.startswith("sklearn")
for algo in ALGORITHMS_LIST:
model = exp.create_model(algo, engine="sklearnex")
parent_library = model.__module__
if algo == "rbfsvm" or algo == "knn":
assert parent_library.startswith("sklearnex")
else:
assert parent_library.startswith("daal4py")