-
-
Notifications
You must be signed in to change notification settings - Fork 281
Adds flow.get_structure and flow.get_subflow (which are complements of each other). Also fixes #564 #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Adds flow.get_structure and flow.get_subflow (which are complements of each other). Also fixes #564 #567
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4ecd35c
fixes minor indentation problems
janvanrijn 1eafe18
initial commit
janvanrijn 37e115c
adds a function to deduce the flow structure
janvanrijn 910a5d3
removes sklearn converter from this PR
janvanrijn 1a68a72
added main functionality
janvanrijn f31849d
fix code quality
janvanrijn edbd556
adds flow name to setup test file
janvanrijn 7845a74
adds functionality to return sklearn parameter name into openml flow …
janvanrijn 7f4b5ac
PEP8 fixes
janvanrijn a05018d
changed structure of PR, such that get_structure is not part of flow …
janvanrijn 046beea
pep8 fix
janvanrijn f46beba
fixes last typo
janvanrijn 4dacb8a
flow name doc string
janvanrijn 4a2c7c8
also added additional filter for task list
janvanrijn 2db7ddb
renamed id argument of parameter object (for code quality)
janvanrijn de93578
fix reference to input id
janvanrijn b2c2696
Merge pull request #582 from openml/develop
janvanrijn 5ac62aa
updated reinitialize model fn
janvanrijn 4aec3ee
removed imputer (deprecated)
janvanrijn 243d9c0
fixes PEP8 problems
janvanrijn 374fcb9
pep8
janvanrijn 7b55bea
PEP8
janvanrijn ff7dd88
incorporated changes by Matthias
janvanrijn 8d6876f
fix 604
janvanrijn 8485090
Merge pull request #606 from openml/fix604
janvanrijn 835e78a
bugfix
janvanrijn d80cd34
flake fix
janvanrijn 428e4b6
import error
janvanrijn fb5dc6a
removed sentence
janvanrijn 786cfcb
updated comment
janvanrijn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| """ | ||
| ========= | ||
| Run Setup | ||
| ========= | ||
|
|
||
| By: Jan N. van Rijn | ||
|
|
||
| One of the key features of the openml-python library is that is allows to | ||
| reinstantiate flows with hyperparameter settings that were uploaded before. | ||
| This tutorial uses the concept of setups. Although setups are not extensively | ||
| described in the OpenML documentation (because most users will not directly | ||
| use them), they form a important concept within OpenML distinguishing between | ||
| hyperparameter configurations. | ||
| A setup is the combination of a flow with all its hyperparameters set. | ||
|
|
||
| A key requirement for reinstantiating a flow is to have the same scikit-learn | ||
| version as the flow that was uploaded. However, this tutorial will upload the | ||
| flow (that will later be reinstantiated) itself, so it can be ran with any | ||
| scikit-learn version that is supported by this library. In this case, the | ||
| requirement of the corresponding scikit-learn versions is automatically met. | ||
|
|
||
| In this tutorial we will | ||
| 1) Create a flow and use it to solve a task; | ||
| 2) Download the flow, reinstantiate the model with same hyperparameters, | ||
| and solve the same task again; | ||
| 3) We will verify that the obtained results are exactly the same. | ||
| """ | ||
| import logging | ||
| import numpy as np | ||
| import openml | ||
| import sklearn.ensemble | ||
| import sklearn.impute | ||
| import sklearn.preprocessing | ||
|
|
||
|
|
||
| root = logging.getLogger() | ||
| root.setLevel(logging.INFO) | ||
|
|
||
| ############################################################################### | ||
| # 1) Create a flow and use it to solve a task | ||
| ############################################################################### | ||
|
|
||
| # first, let's download the task that we are interested in | ||
| task = openml.tasks.get_task(6) | ||
|
|
||
|
|
||
| # we will create a fairly complex model, with many preprocessing components and | ||
| # many potential hyperparameters. Of course, the model can be as complex and as | ||
| # easy as you want it to be | ||
| model_original = sklearn.pipeline.make_pipeline( | ||
| sklearn.impute.SimpleImputer(), | ||
| sklearn.ensemble.RandomForestClassifier() | ||
| ) | ||
|
|
||
|
|
||
| # Let's change some hyperparameters. Of course, in any good application we | ||
| # would tune them using, e.g., Random Search or Bayesian Optimization, but for | ||
| # the purpose of this tutorial we set them to some specific values that might | ||
| # or might not be optimal | ||
| hyperparameters_original = { | ||
| 'simpleimputer__strategy': 'median', | ||
| 'randomforestclassifier__criterion': 'entropy', | ||
| 'randomforestclassifier__max_features': 0.2, | ||
| 'randomforestclassifier__min_samples_leaf': 1, | ||
|
mfeurer marked this conversation as resolved.
|
||
| 'randomforestclassifier__n_estimators': 16, | ||
| 'randomforestclassifier__random_state': 42, | ||
| } | ||
| model_original.set_params(**hyperparameters_original) | ||
|
|
||
| # solve the task and upload the result (this implicitly creates the flow) | ||
| run = openml.runs.run_model_on_task( | ||
| model_original, | ||
| task, | ||
| avoid_duplicate_runs=False) | ||
| run_original = run.publish() # this implicitly uploads the flow | ||
|
|
||
| ############################################################################### | ||
| # 2) Download the flow, reinstantiate the model with same hyperparameters, | ||
| # and solve the same task again. | ||
| ############################################################################### | ||
|
|
||
| # obtain setup id (note that the setup id is assigned by the OpenML server - | ||
| # therefore it was not yet available in our local copy of the run) | ||
| run_downloaded = openml.runs.get_run(run_original.run_id) | ||
| setup_id = run_downloaded.setup_id | ||
|
|
||
| # after this, we can easily reinstantiate the model | ||
| model_duplicate = openml.setups.initialize_model(setup_id) | ||
| # it will automatically have all the hyperparameters set | ||
|
|
||
| # and run the task again | ||
| run_duplicate = openml.runs.run_model_on_task( | ||
| model_duplicate, task, avoid_duplicate_runs=False) | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # 3) We will verify that the obtained results are exactly the same. | ||
| ############################################################################### | ||
|
|
||
| # the run has stored all predictions in the field data content | ||
| np.testing.assert_array_equal(run_original.data_content, | ||
| run_duplicate.data_content) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| from .flow import OpenMLFlow, _copy_server_fields | ||
| from .flow import OpenMLFlow | ||
|
|
||
| from .sklearn_converter import sklearn_to_flow, flow_to_sklearn, _check_n_jobs | ||
| from .sklearn_converter import sklearn_to_flow, flow_to_sklearn, \ | ||
| openml_param_name_to_sklearn | ||
| from .functions import get_flow, list_flows, flow_exists, assert_flows_equal | ||
|
|
||
| __all__ = ['OpenMLFlow', 'create_flow_from_model', 'get_flow', 'list_flows', | ||
| 'sklearn_to_flow', 'flow_to_sklearn', 'flow_exists'] | ||
| __all__ = ['OpenMLFlow', 'get_flow', 'list_flows', 'sklearn_to_flow', | ||
| 'flow_to_sklearn', 'flow_exists', 'openml_param_name_to_sklearn'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from .setup import OpenMLSetup | ||
| from .setup import OpenMLSetup, OpenMLParameter | ||
| from .functions import get_setup, list_setups, setup_exists, initialize_model | ||
|
|
||
| __all__ = ['get_setup', 'list_setups', 'setup_exists', 'initialize_model'] | ||
| __all__ = ['OpenMLSetup', 'OpenMLParameter', 'get_setup', 'list_setups', | ||
| 'setup_exists', 'initialize_model'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.