Skip to content

Commit a6163c3

Browse files
committed
added testcase for initialize model from run
1 parent 2c6d71f commit a6163c3

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/test_runs/test_run_functions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from openml.testing import TestBase
1313
from openml.runs.functions import _run_task_get_arffcontent, _get_seeded_model
1414

15+
from sklearn.naive_bayes import GaussianNB
1516
from sklearn.model_selection._search import BaseSearchCV
1617
from sklearn.tree import DecisionTreeClassifier, ExtraTreeClassifier
1718
from sklearn.preprocessing.imputation import Imputer
@@ -179,6 +180,29 @@ def test_run_and_upload(self):
179180
self.assertTrue(check_res)
180181

181182

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+
182206
def test_get_seeded_model(self):
183207
# randomized models that are initialized without seeds, can be seeded
184208
randomized_clfs = [

0 commit comments

Comments
 (0)