|
12 | 12 | from openml.testing import TestBase |
13 | 13 | from openml.runs.functions import _run_task_get_arffcontent, _get_seeded_model |
14 | 14 |
|
| 15 | +from sklearn.naive_bayes import GaussianNB |
15 | 16 | from sklearn.model_selection._search import BaseSearchCV |
16 | 17 | from sklearn.tree import DecisionTreeClassifier, ExtraTreeClassifier |
17 | 18 | from sklearn.preprocessing.imputation import Imputer |
@@ -179,6 +180,29 @@ def test_run_and_upload(self): |
179 | 180 | self.assertTrue(check_res) |
180 | 181 |
|
181 | 182 |
|
| 183 | + def test_initialize_model_from_run(self): |
| 184 | + clf = sklearn.pipeline.Pipeline(steps=[('Imputer', Imputer(strategy='median')), |
| 185 | + ('VarianceThreshold', VarianceThreshold(threshold=0.05)), |
| 186 | + ('Estimator', GaussianNB())]) |
| 187 | + task = openml.tasks.get_task(11) |
| 188 | + run = openml.runs.run_task(task, clf, avoid_duplicate_runs=False) |
| 189 | + run_ = run.publish() |
| 190 | + run = openml.runs.get_run(run_.run_id) |
| 191 | + |
| 192 | + modelR = openml.runs.initialize_model_from_run(run.run_id) |
| 193 | + modelS = openml.setups.initialize_model(run.setup_id) |
| 194 | + |
| 195 | + flowR = openml.flows.sklearn_to_flow(modelR) |
| 196 | + flowS = openml.flows.sklearn_to_flow(modelS) |
| 197 | + flowL = openml.flows.sklearn_to_flow(clf) |
| 198 | + openml.flows.assert_flows_equal(flowR, flowL) |
| 199 | + openml.flows.assert_flows_equal(flowS, flowL) |
| 200 | + |
| 201 | + self.assertEquals(flowS.components['Imputer'].parameters['strategy'], '"median"') |
| 202 | + self.assertEquals(flowS.components['VarianceThreshold'].parameters['threshold'], '0.05') |
| 203 | + pass |
| 204 | + |
| 205 | + |
182 | 206 | def test_get_seeded_model(self): |
183 | 207 | # randomized models that are initialized without seeds, can be seeded |
184 | 208 | randomized_clfs = [ |
|
0 commit comments