Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Standardize sample weights validation in DummyClassifier #15510

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 4 commits into from
Dec 26, 2019
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/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def fit(self, X, y, sample_weight=None):

self.n_outputs_ = y.shape[1]

check_consistent_length(X, y, sample_weight)
check_consistent_length(X, y)
Copy link
Member

Choose a reason for hiding this comment

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

I think we might still want it here, not strong opinion, though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even though it's checked as part of the added validation?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to avoid redundant checks (even if it doesn't cost much). _check_sample_weight should yield better error messages


if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)
Copy link
Member

Choose a reason for hiding this comment

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

Actually it looks like several PRs were done for this estimator as this was added on the line below in #15505. Please remove the above 3 lines.

Otherwise LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth merging at this point? Looks like the only changes left would be one linting issue and removing sample weight from check_consistent_length. Does it make more sense to close the PR instead?

Expand Down Expand Up @@ -245,7 +245,7 @@ def predict(self, X):
classes_ = [np.array([c]) for c in constant]

y = _random_choice_csc(n_samples, classes_, class_prob,
self.random_state)
self.random_state)
else:
if self._strategy in ("most_frequent", "prior"):
y = np.tile([classes_[k][class_prior_[k].argmax()] for
Expand Down