8000 TST Accelerating ensemble/tests/test_voting.py::test_gridsearch by mohaseeb · Pull Request #21422 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

TST Accelerating ensemble/tests/test_voting.py::test_gridsearch #21422

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
Merged
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
4 changes: 2 additions & 2 deletions sklearn/ensemble/tests/test_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_multilabel():
def test_gridsearch():
"""Check GridSearch support."""
clf1 = LogisticRegression(random_state=1)
clf2 = RandomForestClassifier(random_state=1)
clf2 = RandomForestClassifier(random_state=1, n_estimators=3)
Copy link
Member
@ogrisel ogrisel Oct 23, 2021

Choose a reason for hiding this comment

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

If it's still slow, we could set max_depth=3 to make it run even faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's still slow, we could set max_depth=3 to make it run even faster.

@ogrisel the test case is not part of the 20 slowest anymore.

We tried max_depth=3 locally, but it didn't result in a visible speedup; not sure why.

Copy link
Member

Choose a reason for hiding this comment

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

did you measure the time? I think this should be enough and we should merge :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we did measure the time (for each test impl we ran the test 3 times); the average running time is reported below:

  • original impl: 5.3 seconds
  • ogrisel recommended changes: 0.57 seconds
  • after adding max_depth=3: 0.59 seconds

clf3 = GaussianNB()
eclf = VotingClassifier(
estimators=[("lr", clf1), ("rf", clf2), ("gnb", clf3)], voting="soft"
Expand All @@ -275,7 +275,7 @@ def test_gridsearch():
"weights": [[0.5, 0.5, 0.5], [1.0, 0.5, 0.5]],
}

grid = GridSearchCV(estimator=eclf, param_grid=params)
grid = GridSearchCV(estimator=eclf, param_grid=params, cv=2)
grid.fit(iris.data, iris.target)


Expand Down
0