Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fixed bug handling multi-class classification #19427

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Open
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
21 changes: 17 additions & 4 deletions 21 sklearn/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ def predict(self, X):
return self.classes_[(Y > 0).astype(int)]
return self.classes_[Y.argmax(axis=1)]

def decision_function(self, X):
@_deprecate_positional_args
def decision_function(self, X, random_state='warn'):
"""Decision function for the OneVsOneClassifier.

The decision values for the samples are computed by adding the
Expand All @@ -737,6 +738,8 @@ def decision_function(self, X):
Parameters
----------
X : array-like of shape (n_samples, n_features)
init: issues a warning by default and makes it possible to choose
between the past or future behaviour.

Returns
-------
Expand Down Expand Up @@ -765,9 +768,19 @@ def decision_function(self, X):
return Y[:, 1]
return Y

@property
def n_classes_(self):
return len(self.classes_)
if random_state == 'warn':
warnings.warn(
"'random_state' will be set to None starting from 1.2 which"
"means that results will differ at every function call."
"Set 'random_state' to an integer value to silence this"
"warning, or to 0 to keep the behavior of versions <1.0",
FutureWarning
)
random_state = 0

@property
def n_classes_(self):
return len(self.classes_)

# TODO: Remove in 1.1
# mypy error: Decorated property not supported
Expand Down
18 changes: 15 additions & 3 deletions 18 sklearn/svm/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ def _validate_targets(self, y):

return np.asarray(y, dtype=np.float64, order='C')

def decision_function(self, X):
@_deprecate_positional_args
def decision_function(self, X, random_state='warn'):
"""Evaluates the decision function for the samples in X.

Parameters
Expand Down Expand Up @@ -591,15 +592,26 @@ def decision_function(self, X):
return _ovr_decision_function(dec < 0, -dec, len(self.classes_))
return dec

if random_state == 'warn':
warnings.warn(
"'random_state' will be set to None starting from 1.2 which"
"means that results will differ at every function call."
"Set 'random_state' to an integer value to silence this"
"warning, or to 0 to keep the behavior of versions <1.0",
FutureWarning
)
random_state = 0

def predict(self, X):
"""Perform classification on samples in X.

For an one-class model, +1 or -1 is returned.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features) or \
(n_samples_test, n_samples_train)
X : {array-like, sparse matrix} of shape
(n_samples, n_features) or \
(n_samples_test, n_samples_train)
For kernel="precomputed", the expected shape of X is
(n_samples_test, n_samples_train).

Expand Down
2 changes: 1 addition & 1 deletion 2 sklearn/utils/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ def _ovr_decision_function(predictions, confidences, n_classes):
# of 1 vote.
transformed_confidences = (sum_of_confidences /
(3 * (np.abs(sum_of_confidences) + 1)))
return votes + transformed_confidences
return votes + transformed_confidences - (n_classes - 1) / 2
Morty Proxy This is a proxified and sanitized view of the page, visit original site.