Skip to content
Merged
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
24 changes: 0 additions & 24 deletions python/cuml/cuml/metrics/hinge_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#
import warnings

import cupy as cp
import numpy as np

Expand All @@ -20,8 +18,6 @@ def hinge_loss(
pred_decision,
labels=None,
sample_weight=None,
*,
sample_weights="deprecated",
) -> float:
"""
Calculates non-regularized hinge loss. Adapted from scikit-learn hinge loss.
Expand All @@ -42,31 +38,11 @@ def hinge_loss(
sample_weight : array-like of shape (n_samples,), default=None
Sample weights to be used for computing the average.

sample_weights : array-like, default="deprecated"
Deprecated alias for ``sample_weight``.

.. deprecated:: 26.06
``sample_weights`` was renamed to ``sample_weight`` and will be
removed in 26.08.

Returns
-------
loss : float
The average hinge loss.
"""
# Handle the deprecated `sample_weights` alias.
if not (
isinstance(sample_weights, str) and sample_weights == "deprecated"
):
warnings.warn(
"`sample_weights` was renamed to `sample_weight` in 26.06 and "
"will be removed in 26.08.",
FutureWarning,
stacklevel=2,
)
if sample_weight is None:
sample_weight = sample_weights

pred_decision = check_array(
pred_decision,
ensure_2d=False,
Expand Down
49 changes: 4 additions & 45 deletions python/cuml/cuml/naive_bayes/naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#
import warnings

import cupy as cp
import cupyx
import numpy as np
Expand Down Expand Up @@ -624,7 +622,6 @@ def partial_fit(
X,
y,
classes=None,
sample_weight="deprecated",
) -> "_BaseDiscreteNB":
"""
Incremental fit on a batch of samples.
Expand All @@ -651,23 +648,12 @@ def partial_fit(
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted
in subsequent calls.
sample_weight : array-like of shape (n_samples)

.. deprecated:: 26.06

The `sample_weight` argument was deprecated in version 26.06
and will be removed in version 26.08. `sample_weight` was
previously silently ignored; we're opting to remove the
parameter for now rather than having a parameter that's not
supported.

Returns
-------
self : object
"""
return self._partial_fit(
X, y, sample_weight=sample_weight, classes=classes
)
return self._partial_fit(X, y, classes=classes)
Comment thread
divyegala marked this conversation as resolved.

@nvtx.annotate(
message="naive_bayes._BaseDiscreteNB._partial_fit",
Expand All @@ -677,40 +663,22 @@ def _partial_fit(
self,
X,
y,
sample_weight="deprecated",
classes=None,
reset=False,
convert_dtype=True,
) -> "_BaseDiscreteNB":
if isinstance(sample_weight, str) and sample_weight == "deprecated":
sample_weight = None
else:
warnings.warn(
"`sample_weight` was deprecated in version 26.06 and will be removed "
"in version 26.08. Passing sample weights was previously silently "
"ignored; we're opting to remove the parameter for now rather "
"than continue having a parameter that's not supported.",
FutureWarning,
)

if self.alpha < 0:
raise ValueError(f"Expected alpha >= 0, got {self.alpha}")

classes, reset = self._check_classes(classes, reset)
X, y, classes, sample_weight = self._check_fit(
X, y, classes, _ = self._check_fit(
X,
y,
classes=classes,
sample_weight=sample_weight,
reset=reset,
convert_dtype=convert_dtype,
)

if sample_weight is not None:
raise NotImplementedError(
"sample_weight support is not implemented"
)

if reset:
self.classes_ = classes
self.n_classes_ = self.classes_.shape[0]
Expand All @@ -728,7 +696,7 @@ def _partial_fit(
return self

@run_in_internal_context
def fit(self, X, y, sample_weight="deprecated") -> "_BaseDiscreteNB":
def fit(self, X, y) -> "_BaseDiscreteNB":
"""
Fit Naive Bayes classifier according to X, y

Expand All @@ -739,17 +707,8 @@ def fit(self, X, y, sample_weight="deprecated") -> "_BaseDiscreteNB":
n_features is the number of features.
y : array-like shape (n_samples)
Target values.
sample_weight : array-like of shape (n_samples)

.. deprecated:: 26.06

The `sample_weight` argument was deprecated in version 26.06
and will be removed in version 26.08. `sample_weight` was
previously silently ignored; we're opting to remove the
parameter for now rather than having a parameter that's not
supported.
"""
return self._partial_fit(X, y, reset=True, sample_weight=sample_weight)
return self._partial_fit(X, y, reset=True)

def _init_counters(self, n_effective_classes, n_features, dtype):
self.class_count_ = cp.zeros(
Expand Down
10 changes: 0 additions & 10 deletions python/cuml/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,16 +1959,6 @@ def test_hinge_loss_multiclass_missing_labels():
cuml_hinge(np.array([0, 1, 2]), rng.randn(3, 2))


def test_hinge_loss_sample_weights_deprecated():
y_true = np.array([-1, 1, 1, -1])
pred_decision = np.array([-2.18, 2.36, 0.09, -1.0])
sw = np.array([1.0, 2.0, 1.0, 1.0])
expected = cuml_hinge(y_true, pred_decision, sample_weight=sw)
with pytest.warns(FutureWarning, match="sample_weights"):
result = cuml_hinge(y_true, pred_decision, sample_weights=sw)
np.testing.assert_allclose(result, expected)


@pytest.mark.parametrize(
"nfeatures",
[
Expand Down
26 changes: 0 additions & 26 deletions python/cuml/tests/test_naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,29 +610,3 @@ def test_categorical_parameters(

assert_allclose(y_log_prob, y_log_prob_sk, rtol=1e-4, atol=1e-10)
assert_array_equal(y_hat, y_hat_sk)


@pytest.mark.parametrize(
"cls", [BernoulliNB, CategoricalNB, ComplementNB, MultinomialNB]
)
def test_sample_weight_deprecated(cls):
X = np.array([[1, 2], [3, 4], [5, 6]])
y = np.array([0, 1, 1])
classes = np.array([0, 1])
sample_weight = np.full(3, 0.5, dtype="float32")

# Passing _anything_ leads to a warning, even if it's supported
with pytest.warns(FutureWarning, match="sample_weight"):
cls().fit(X, y, sample_weight=None)
with pytest.warns(FutureWarning, match="sample_weight"):
cls().partial_fit(X, y, classes=classes, sample_weight=None)

# Passing an actual array also errors
with pytest.raises(NotImplementedError, match="sample_weight"):
with pytest.warns(FutureWarning, match="sample_weight"):
cls().fit(X, y, sample_weight=sample_weight)
with pytest.raises(NotImplementedError, match="sample_weight"):
with pytest.warns(FutureWarning, match="sample_weight"):
cls().partial_fit(
X, y, classes=classes, sample_weight=sample_weight
)
32 changes: 0 additions & 32 deletions python/cuml/tests/test_sklearn_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,50 +333,18 @@ def _all_cuml_estimators():
BernoulliNB: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_classifier_data_not_an_array": "bug in reflection prevents this",
"check_sample_weights_pandas_series": "sample_weight not implemented",
"check_sample_weights_not_an_array": "sample_weight not implemented",
"check_sample_weights_shape": "sample_weight not implemented",
"check_sample_weight_equivalence_on_dense_data": "sample_weight not implemented",
"check_sample_weights_list": "sample_weight not implemented",
"check_sample_weights_not_overwritten": "sample_weight not implemented",
"check_sample_weight_equivalence_on_sparse_data": "sample_weight not implemented",
"check_classifiers_one_label_sample_weights": "sample_weight not implemented",
},
ComplementNB: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_classifier_data_not_an_array": "bug in reflection prevents this",
"check_sample_weights_pandas_series": "sample_weight not implemented",
"check_sample_weights_not_an_array": "sample_weight not implemented",
"check_sample_weights_shape": "sample_weight not implemented",
"check_sample_weight_equivalence_on_dense_data": "sample_weight not implemented",
"check_sample_weights_list": "sample_weight not implemented",
"check_sample_weights_not_overwritten": "sample_weight not implemented",
"check_sample_weight_equivalence_on_sparse_data": "sample_weight not implemented",
"check_classifiers_one_label_sample_weights": "sample_weight not implemented",
},
CategoricalNB: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_classifier_data_not_an_array": "bug in reflection prevents this",
"check_sample_weights_pandas_series": "sample_weight not implemented",
"check_sample_weights_not_an_array": "sample_weight not implemented",
"check_sample_weights_shape": "sample_weight not implemented",
"check_sample_weight_equivalence_on_dense_data": "sample_weight not implemented",
"check_sample_weights_list": "sample_weight not implemented",
"check_sample_weights_not_overwritten": "sample_weight not implemented",
"check_sample_weight_equivalence_on_sparse_data": "sample_weight not implemented",
"check_classifiers_one_label_sample_weights": "sample_weight not implemented",
},
MultinomialNB: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_classifier_data_not_an_array": "bug in reflection prevents this",
"check_sample_weights_pandas_series": "sample_weight not implemented",
"check_sample_weights_not_an_array": "sample_weight not implemented",
"check_sample_weights_shape": "sample_weight not implemented",
"check_sample_weight_equivalence_on_dense_data": "sample_weight not implemented",
"check_sample_weights_list": "sample_weight not implemented",
"check_sample_weights_not_overwritten": "sample_weight not implemented",
"check_sample_weight_equivalence_on_sparse_data": "sample_weight not implemented",
"check_classifiers_one_label_sample_weights": "sample_weight not implemented",
},
}

Expand Down
Loading