8000 [MRG] BUG Fixes duck typing in voting by thomasjpfan · Pull Request #14287 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] BUG Fixes duck typing in voting #14287

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 5 commits into from
Jul 12, 2019
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
11 changes: 7 additions & 4 deletions doc/whats_new/v0.22.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ Changelog
:mod:`sklearn.ensemble`
.......................

- |Feature| :class:`ensemble.HistGradientBoostingClassifier` and
:class:`ensemble.HistGradientBoostingRegressor` have an additional
parameter called `warm_start` that enables warm starting. :pr:`14012` by
:user:`Johann Faouzi <johannfaouzi>`.

- |Fix| :class:`ensemble.HistGradientBoostingClassifier` and
:class:`ensemble.HistGradientBoostingRegressor` now bin the training and
validation data separately to avoid any data leak. :pr:`13933` by
`Nicolas Hug`_.

- |Feature| :class:`ensemble.HistGradientBoostingClassifier` and
:class:`ensemble.HistGradientBoostingRegressor` have an additional
parameter called `warm_start` that enables warm starting. :pr:`14012` by
:user:`Johann Faouzi <johannfaouzi>`.
- |Fix| :func:`ensemble.VotingClassifier.predict_proba` will no longer be
present when `voting='hard'`. :pr:`14287` by `Thomas Fan`_.

- |Enhancement| :class:`ensemble.HistGradientBoostingClassifier` the training
loss or score is now monitored on a class-wise stratified subsample to
Expand Down
7 changes: 6 additions & 1 deletion sklearn/ensemble/tests/test_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def test_predictproba_hardvoting():
('lr2', LogisticRegression())],
voting='hard')
msg = "predict_proba is not available when voting='hard'"
assert_raise_message(AttributeError, msg, eclf.predict_proba, X)
with pytest.raises(AttributeError, match=msg):
eclf.predict_proba

assert not hasattr(eclf, "predict_proba")
eclf.fit(X, y)
assert not hasattr(eclf, "predict_proba")


def test_notfitted():
Expand Down
6 changes: 3 additions & 3 deletions sklearn/ensemble/voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ def _collect_probas(self, X):

def _predict_proba(self, X):
"""Predict class probabilities for X in 'soft' voting """
if self.voting == 'hard':
raise AttributeError("predict_proba is not available when"
" voting=%r" % self.voting)
check_is_fitted(self, 'estimators_')
avg = np.average(self._collect_probas(X), axis=0,
weights=self._weights_not_none)
Expand All @@ -335,6 +332,9 @@ def predict_proba(self):
avg : array-like, shape (n_samples, n_classes)
Weighted average probability for each class per sample.
"""
if self.voting == 'hard':
raise AttributeError("predict_proba is not available when"
" voting=%r" % self.voting)
return self._predict_proba

def transform(self, X):
Expand Down
0