Skip to content

Commit 3193993

Browse files
add RidgeClassifier
1 parent 9a4b75a commit 3193993

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

sklearn/linear_model/ridge.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,17 @@ def fit(self, X, y, sample_weight=None):
590590
-------
591591
self : returns an instance of self.
592592
"""
593-
if sample_weight is None:
594-
sample_weight = 1.
595-
596593
self._label_binarizer = LabelBinarizer(pos_label=1, neg_label=-1)
597594
Y = self._label_binarizer.fit_transform(y)
598595
if not self._label_binarizer.y_type_.startswith('multilabel'):
599596
y = column_or_1d(y, warn=True)
600597

601-
# modify the sample weights with the corresponding class weight
602-
sample_weight = (sample_weight *
603-
compute_sample_weight(self.class_weight, y))
598+
if self.class_weight:
599+
if sample_weight is None:
600+
sample_weight = 1.
601+
# modify the sample weights with the corresponding class weight
602+
sample_weight = (sample_weight *
603+
compute_sample_weight(self.class_weight, y))
604604

605605
super(RidgeClassifier, self).fit(X, Y, sample_weight=sample_weight)
606606
return self
@@ -1070,16 +1070,18 @@ def fit(self, X, y, sample_weight=None):
10701070
self : object
10711071
Returns self.
10721072
"""
1073-
if sample_weight is None:
1074-
sample_weight = 1.
1075-
10761073
self._label_binarizer = LabelBinarizer(pos_label=1, neg_label=-1)
10771074
Y = self._label_binarizer.fit_transform(y)
10781075
if not self._label_binarizer.y_type_.startswith('multilabel'):
10791076
y = column_or_1d(y, warn=True)
1080-
# modify the sample weights with the corresponding class weight
1081-
sample_weight = (sample_weight *
1082-
compute_sample_weight(self.class_weight, y))
1077+
1078+
if self.class_weight:
1079+
if sample_weight is None:
1080+
sample_weight = 1.
1081+
# modify the sample weights with the corresponding class weight
1082+
sample_weight = (sample_weight *
1083+
compute_sample_weight(self.class_weight, y))
1084+
10831085
_BaseRidgeCV.fit(self, X, Y, sample_weight=sample_weight)
10841086
return self
10851087

0 commit comments

Comments
 (0)