-
Notifications
You must be signed in to change notification settings - Fork 23
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
Cross validation of Pipeline/estimators using MLDataset / xarray.Dataset #221
Closed
Closed
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
55959a5
cross validation of MLDataset Pipeline
396f9aa
changes with CV sampling
33bac56
changes to cv_cache
b422e68
closer to working cross validation for MLDataset
d45d4e1
CV / xarray experimentation - work in progress
92054c9
MLDataset cross validation working for pipeline of 1 step that is uns…
35450c1
wrapped sklearn classes need to wrap score methods as fit, predict, o…
f86a079
update tests;fix cross validation with most data structures
5cf646f
a couple tests for Python 2.7
744109a
avoid dask-searchcv test in conda.recipe;add test_config.yml to MANIF…
1e7bec8
remove print statement
83437f5
ensure test_config.yaml included in pkg
de9efd0
remove elm.mldataset.cross_validation - modify environment.yml for el…
6267041
fix usage of is_arr utility to separate X, y tuple
66013e6
1850 passing tests
a91caf6
dask-searchcv in meta.yaml
e9b5d85
use elm/label/dev and elm for CI installs
f6ef7c8
change earthio version for fixing CI build
948efe5
ensure EARTHIO_CHANNEL_STR is set correctly in .travis.yml
edbe1f5
ensure ANACONDA_UPLOAD_USER is defined in .travis for pkg upload
6304e37
change order of channels to ensure dask-searchcv comes from elm
8a6d46f
subset the number of tests being run in CI
21a18d9
better diagnostics on upload failure in CI
8ad7b4c
remove earthio from CI
9a1734d
be sure to create env from elm's conda build output
dc47f65
remove diagnostic print from deploy section
00ea1be
refactor to simplify changes in dask-searchcv
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 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,2 +1,3 @@ | ||
include elm/config/defaults/environment_vars_spec.yaml | ||
include elm/config/defaults/config_standard.yaml | ||
include elm/tests/test_config.yaml |
This file contains 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 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 @@ | ||
from elm.mldataset.util import is_mldataset |
This file contains 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,39 @@ | ||
import numpy as np | ||
import dask.array as da | ||
|
||
from collections import Sequence | ||
|
||
|
||
def is_mldataset(arr, raise_err=False): | ||
try: | ||
from xarray_filters import MLDataset | ||
from xarray import Dataset | ||
return True | ||
except Exception as e: | ||
MLDataset = Dataset = None | ||
if not raise_err: | ||
return False | ||
# Much of the ML logic | ||
# wrapping Xarray would fail | ||
# if only xarray and not Xarray_filters | ||
# is installed, but when xarray_filters | ||
# is installed, xarray.Dataset can be | ||
# used | ||
raise ValueError('Cannot use cross validation for xarray Dataset without xarray_filters') | ||
return MLDataset and isinstance(arr, (MLDataset, Dataset)) | ||
|
||
|
||
def is_arr(arr, raise_err=False): | ||
is_ml = is_mldataset(arr, raise_err=raise_err) | ||
return is_ml or isinstance(arr, (np.ndarray, da.Array)) | ||
|
||
|
||
def _split_transformer_result(Xt, y): | ||
if isinstance(Xt, Sequence) and len(Xt) == 2 and is_arr(Xt[1]): | ||
Xt, new_y = Xt | ||
else: | ||
new_y = y | ||
if y is None and new_y is not None: | ||
y = new_y | ||
assert not isinstance(y, tuple), repr((Xt, y, new_y)) | ||
return Xt, y |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -36,17 +36,6 @@ def get_module_classes(m): | |
return {attr: getattr(module, attr) for attr in attrs} | ||
|
||
|
||
def patch_cls(cls): | ||
|
||
class Wrapped(SklearnMixin, cls): | ||
_cls = cls | ||
__init__ = cls.__init__ | ||
_cls_name = cls.__name__ | ||
name = 'Elm{}'.format(cls.__name__) | ||
globals()[name] = Wrapped | ||
return globals()[name] | ||
|
||
|
||
_all = [] | ||
_seen = set() | ||
ALL_STEPS = {} | ||
|
@@ -55,12 +44,20 @@ class Wrapped(SklearnMixin, cls): | |
for cls in get_module_classes(m).values(): | ||
if cls.__name__ in _seen: | ||
continue | ||
if not m in cls.__module__: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just checking that we are getting |
||
continue | ||
_seen.add(cls.__name__) | ||
w = patch_cls(cls) | ||
if any(s in cls.__name__ for s in SKIP): | ||
name = cls.__name__ | ||
if any(s in name for s in SKIP): | ||
continue | ||
this_module[cls.__name__] = w | ||
ALL_STEPS[(m, cls.__name__)] = w | ||
class Wrapped(SklearnMixin, cls): | ||
_cls = cls | ||
__init__ = cls.__init__ | ||
_cls_name = name | ||
|
||
globals()[name] = Wrapped | ||
this_module[cls.__name__] = globals()[name] | ||
ALL_STEPS[(m, cls.__name__)] = globals()[name] | ||
this_module = Namespace(**this_module) | ||
if m == 'cluster.bicluster': | ||
bicluster = this_module # special case (dotted name) | ||
|
@@ -75,5 +72,4 @@ class Wrapped(SklearnMixin, cls): | |
del _all | ||
del m | ||
del this_module | ||
del w | ||
del _seen |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currently working on simplifying this function - checking what is actually needed.