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

Skip to content

Commit de9de2d

Browse files
committed
FIX scikit-learn#3485: class_weight='auto' on SGDClassifier
1 parent a2eb0d7 commit de9de2d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

doc/whats_new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Bug fixes
3535
and ``pandas.DataFrame`` in recent versions of pandas. By
3636
`Gael Varoquaux`_.
3737

38+
- Fixed a regression for :class:`linear_model.SGDClassifier` with
39+
``class_weight="auto"`` on data with non-contiguous labels. By
40+
`Olivier Grisel`_.
41+
3842

3943
.. _changes_0_15:
4044

sklearn/linear_model/stochastic_gradient.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,8 @@ def _partial_fit(self, X, y, alpha, C,
329329
n_classes = self.classes_.shape[0]
330330

331331
# Allocate datastructures from input arguments
332-
y_ind = np.searchsorted(self.classes_, y) # XXX use a LabelBinarizer?
333332
self._expanded_class_weight = compute_class_weight(self.class_weight,
334-
self.classes_,
335-
y_ind)
333+
self.classes_, y)
336334
sample_weight = self._validate_sample_weight(sample_weight, n_samples)
337335

338336
if self.coef_ is None or coef_init is not None:

sklearn/linear_model/tests/test_sgd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def test_underflow_or_overlow():
847847
assert_array_equal(np.unique(y), [0, 1])
848848

849849
model = SGDClassifier(alpha=0.1, loss='squared_hinge', n_iter=500)
850-
850+
851851
# smoke test: model is stable on scaled data
852852
model.fit(scale(X), y)
853853

0 commit comments

Comments
 (0)