8000 Merge pull request #4295 from ragv/sigmoid_decision_fn · scikit-learn/scikit-learn@4be6214 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4be6214

Browse files
committed
Merge pull request #4295 from ragv/sigmoid_decision_fn
[MRG + 3] ENH linearly scale to (-0.5, 0.5) instead of [-0.4, 0.4]
2 parents dcdb7e7 + 342e6e4 commit 4be6214

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

sklearn/multiclass.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def fit(self, X, y):
511511

512512
def predict(self, X):
513513
"""Estimate the best class label for each sample in X.
514-
514+
515515
This is implemented as ``argmax(decision_function(X), axis=1)`` which
516516
will return the label of the class with most votes by estimators
517517
predicting the outcome of a decision for each possible class pair.
@@ -532,7 +532,7 @@ def predict(self, X):
532532
def decision_function(self, X):
533533
"""Decision function for the OneVsOneClassifier.
534534
535-
The decision values for the samples are computed by adding the
535+
The decision values for the samples are computed by adding the
536536
normalized sum of pair-wise classification confidence levels to the
537537
votes in order to disambiguate between the decision values when the
538538
votes for all the classes are equal leading to a tie.
@@ -569,9 +569,14 @@ def decision_function(self, X):
569569
if max_confidences == min_confidences:
570570
return votes
571571

572-
# Scale the sum_of_confidences to [-0.4, 0.4] and add it with votes
573-
return votes + sum_of_confidences * \
574-
(0.4 / max(abs(max_confidences), abs(min_confidences)))
572+
# Scale the sum_of_confidences to (-0.5, 0.5) and add it with votes.
573+
# The motivation is to use confidence levels as a way to break ties in
574+
# the votes without switching any decision made based on a difference
575+
# of 1 vote.
576+
eps = np.finfo(sum_of_confidences.dtype).eps
577+
max_abs_confidence = max(abs(max_confidences), abs(min_confidences))
578+
scale = (0.5 - eps) / max_abs_confidence
579+
return votes + sum_of_confidences * scale
575580

576581

577582
@deprecated("fit_ecoc is deprecated and will be removed in 0.18."

0 commit comments

Comments
 (0)
0