Skip to content

[MRG+1] Enabling sample weights for 3 of the 4 logistic regression solvers #5204

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

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ Enhancements
- Added optional parameter ``warm_start`` in
:class:`linear_model.LogisticRegression`. If set to True, the solvers ``lbfgs``, ``newton-cg`` and ``sag`` will be initialized with the coefficients computed in the previous fit. By `Tom Dupre la Tour`_.

- Added ``sample_weight`` support to :class:`linear_model.LogisticRegression` for
the ``lbfgs``, ``newton-cg``, and ``sag`` solvers. By `Valentin Stolbunov`_.


Bug fixes
.........

Expand Down Expand Up @@ -3676,3 +3680,4 @@ David Huard, Dave Morrill, Ed Schofield, Travis Oliphant, Pearu Peterson.
.. _Daniel Galvez: https://github.com/galv
.. _Jacob Schreiber: https://github.com/jmschrei
.. _Ankur Ankan: https://github.com/ankurankan
.. _Valentin Stolbunov: http://vstolbunov.com
8 changes: 8 additions & 0 deletions sklearn/ensemble/bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..externals.six.moves import zip
from ..metrics import r2_score, accuracy_score
from ..tree import DecisionTreeClassifier, DecisionTreeRegressor
from ..linear_model import LogisticRegression
from ..utils import check_random_state, check_X_y, check_array, column_or_1d
from ..utils.random import sample_without_replacement
from ..utils.validation import has_fit_parameter, check_is_fitted
Expand Down Expand Up @@ -52,6 +53,13 @@ def _parallel_build_estimators(n_estimators, ensemble, X, y, sample_weight,
bootstrap_features = ensemble.bootstrap_features
support_sample_weight = has_fit_parameter(ensemble.base_estimator_,
"sample_weight")
# Logistic regression does not support sample weights with liblinear
# TODO: Remove this check when liblinear is patched to support
# sample weights
if (isinstance(ensemble.base_estimator_, LogisticRegression) and
(ensemble.base_estimator_.solver == 'liblinear')):
support_sample_weight = False

if not support_sample_weight and sample_weight is not None:
raise ValueError("The base estimator doesn't support sample weight")

Expand Down
Loading