Skip to content

Commit

Permalink
Replaced Label Encoder with Label Binarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
MechCoder committed Jul 22, 2014
1 parent 12adea8 commit 53e2593
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions sklearn/linear_model/logistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

from .base import LinearClassifierMixin, SparseCoefMixin, BaseEstimator
from ..feature_selection.from_model import _LearntSelectorMixin
from ..preprocessing import LabelEncoder
from ..preprocessing import LabelEncoder, LabelBinarizer
from ..svm.base import BaseLibLinear
from ..utils import as_float_array
from ..utils import as_float_array, check_arrays
from ..externals.joblib import Parallel, delayed
from ..cross_validation import check_cv
from ..utils.optimize import newton_cg
Expand Down Expand Up @@ -553,23 +553,14 @@ def fit(self, X, y):
self : object
Returns self.
"""
self._enc = LabelEncoder()
X = as_float_array(X, copy=False)
y = self._enc.fit_transform(y)
X, y = check_arrays(X, y, copy=False)
self._lb = LabelBinarizer(neg_label=-1, pos_label=1)
y = np.squeeze(self._lb.fit_transform(y))
if len(self.classes_) != 2:
raise ValueError("LogisticRegressionCV works only on 2 "
"class problems. Please use "
"OneVsOneClassifier or OneVsRestClassifier")

if X.shape[0] != y.shape[0]:
raise ValueError("X and y have incompatible shapes.\n"
"X has %s samples, but y has %s." %
(X.shape[0], y.shape[0]))

# Transform to [-1, 1] classes, as y is [0, 1]
y *= 2
y -= 1

# init cross-validation generator
cv = check_cv(self.cv, X, y, classifier=True)
folds = list(cv)
Expand Down Expand Up @@ -608,5 +599,5 @@ def fit(self, X, y):

@property
def classes_(self):
return self._enc.classes_
return self._lb.classes_

0 comments on commit 53e2593

Please sign in to comment.