-
-
Notifications
You must be signed in to change notification settings - Fork 260
support for non dask arrays for HyperbandSearchCV #751
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
6b3ad51
101e6a9
fe154c6
a73e6ec
cd5645f
0017e09
f7c01c7
ef2956a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,11 +204,13 @@ async def _fit( | |
| assert len(X_train) == len(y_train) | ||
|
|
||
| train_eg = await client.gather(client.map(len, y_train)) | ||
| msg = "[CV%s] For training there are between %d and %d examples in each chunk" | ||
| logger.info(msg, prefix, min(train_eg), max(train_eg)) | ||
|
|
||
| # Order by which we process training data futures | ||
| order = [] | ||
| ### start addition ### | ||
| min_samples = min(train_eg) if len(train_eg) else len(y_train) | ||
| max_samples = max(train_eg) if len(train_eg) else len(y_train) | ||
|
|
||
| msg = "[CV%s] For training there are between %d and %d examples in each chunk" | ||
| logger.info(msg, prefix, min_samples, max_samples) | ||
|
|
||
| def get_futures(partial_fit_calls): | ||
| """Policy to get training data futures | ||
|
|
@@ -218,13 +220,20 @@ def get_futures(partial_fit_calls): | |
| This function handles that policy internally, and also controls random | ||
| access to training data. | ||
| """ | ||
| if dask.is_dask_collection(y_train): | ||
|
||
| return X_train, y_train | ||
|
|
||
| # Shuffle blocks going forward to get uniform-but-random access | ||
| while partial_fit_calls >= len(order): | ||
| L = list(range(len(X_train))) | ||
| rng.shuffle(L) | ||
| order.extend(L) | ||
| j = order[partial_fit_calls] | ||
| return X_train[j], y_train[j] | ||
| ### end addition ### | ||
|
||
|
|
||
| # Order by which we process training data futures | ||
| order = [] | ||
|
|
||
| # Submit initial partial_fit and score computations on first batch of data | ||
| X_future, y_future = get_futures(0) | ||
|
|
@@ -566,7 +575,8 @@ def _get_train_test_split(self, X, y, **kwargs): | |
| X, y : dask.array.Array | ||
| """ | ||
| if self.test_size is None: | ||
| test_size = min(0.2, 1 / X.npartitions) | ||
| npartitions = getattr(X, 'npartitions', 1) | ||
| test_size = min(0.2, 1 / npartitions) | ||
| else: | ||
| test_size = self.test_size | ||
| X_train, X_test, y_train, y_test = train_test_split( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
| from dask_ml.model_selection import HyperbandSearchCV | ||
| from dask_ml.datasets import make_classification | ||
| from distributed.utils_test import gen_cluster | ||
| from sklearn.linear_model import SGDClassifier | ||
|
|
||
|
|
||
| @gen_cluster(client=True) | ||
| def test_pandas(c, s, a, b): | ||
|
||
| X, y = make_classification(chunks=100) | ||
| X, y = pd.DataFrame(X.compute()), pd.Series(y.compute()) | ||
|
||
|
|
||
| est = SGDClassifier(tol=1e-3) | ||
| param_dist = {'alpha': np.logspace(-4, 0, num=1000), | ||
| 'loss': ['hinge', 'log', 'modified_huber', 'squared_hinge'], | ||
| 'average': [True, False]} | ||
|
|
||
| search = HyperbandSearchCV(est, param_dist) | ||
| search.fit(X, y, classes=y.unique()) | ||
| assert search.best_params_ | ||
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.
Style nit: can this comment be removed?