Skip to content
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

IncrementalSearch edge cases #373

Merged
merged 4 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dask_ml/model_selection/_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,18 @@ def inverse(time):

current_time_step = time_step + 1
next_time_step = current_time_step

if inverse(current_time_step) == 0:
# we'll never get out of here
next_time_step = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the inverse function itself should never produce non-positive values? I can imagine placing the min(1, there instead, or perhaps using math.ceil rather than int

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this additional if check is still necessary, even if we change inverse to be always positive. When these start off at the same value (whether it's 0 or 1), we get stuck in a cycle where next_time_step is increasing, making the inverse(current_time_step) == inverse(next_time_step) condition even more false.


while inverse(current_time_step) == inverse(next_time_step) and (
not self.patience
or next_time_step - current_time_step < self.scores_per_fit
):
next_time_step += 1

target = inverse(next_time_step)
target = max(1, inverse(next_time_step))
best = toolz.topk(target, info, key=lambda k: info[k][-1]["score"])

if len(best) == 1:
Expand Down
23 changes: 23 additions & 0 deletions tests/model_selection/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,26 @@ def test_transform(c, s, a, b):
X_, = yield c.compute([X])
result = search.transform(X_)
assert result.shape == (100, search.best_estimator_.n_clusters)


@gen_cluster(client=True)
def test_small(c, s, a, b):
X, y = make_classification(n_samples=100, n_features=5, chunks=(10, 5))
model = SGDClassifier(tol=1e-3, penalty="elasticnet")
params = {"alpha": [0.1, 0.5, 0.75, 1.0]}
search = IncrementalSearch(model, params, n_initial_parameters="grid")
yield search.fit(X, y, classes=[0, 1])
X_, = yield c.compute([X])
search.predict(X_)


@gen_cluster(client=True)
def test_smaller(c, s, a, b):
# infininte loop
X, y = make_classification(n_samples=100, n_features=5, chunks=(10, 5))
model = SGDClassifier(tol=1e-3, penalty="elasticnet")
params = {"alpha": [0.1, 0.5]}
search = IncrementalSearch(model, params, n_initial_parameters="grid")
yield search.fit(X, y, classes=[0, 1])
X_, = yield c.compute([X])
search.predict(X_)