Skip to content

Commit a5c1d3c

Browse files
committed
CLN no extra methods for HalfSquaredError
1 parent df072e4 commit a5c1d3c

File tree

1 file changed

+0
-45
lines changed

1 file changed

+0
-45
lines changed

sklearn/_loss/loss.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -459,51 +459,6 @@ def __init__(self, sample_weight=None):
459459
else:
460460
self.constant_hessian = False
461461

462-
def gradient(
463-
self,
464-
y_true,
465-
raw_prediction,
466-
sample_weight=None,
467-
gradient=None,
468-
n_threads=1,
469-
):
470-
# Be graceful to shape (n_samples, 1) -> (n_samples,)
471-
if raw_prediction.ndim == 2 and raw_prediction.shape[1] == 1:
472-
raw_prediction = raw_prediction.squeeze(1)
473-
if gradient is not None and gradient.ndim == 2 and gradient.shape[1] == 1:
474-
gradient = gradient.squeeze(1)
475-
476-
# gradient = raw_prediction - y_true is easier in numpy
477-
gradient = np.subtract(raw_prediction, y_true, out=gradient)
478-
if sample_weight is None:
479-
return gradient
480-
else:
481-
return np.multiply(sample_weight, gradient, out=gradient)
482-
483-
def gradient_hessian(
484-
self,
485-
y_true,
486-
raw_prediction,
487-
sample_weight=None,
488-
gradient=None,
489-
hessian=None,
490-
n_threads=1,
491-
):
492-
# easier in numpy
493-
gradient = self.gradient(
494-
y_true, raw_prediction, sample_weight, gradient, hessian
495-
)
496-
if hessian is None:
497-
hessian = np.empty_like(gradient)
498-
elif hessian.ndim == 2 and hessian.shape[1] == 1:
499-
# Be graceful to shape (n_samples, 1) -> (n_samples,)
500-
hessian = hessian.squeeze(1)
501-
if sample_weight is None:
502-
hessian.fill(1)
503-
else:
504-
np.copyto(hessian, sample_weight)
505-
return gradient, hessian
506-
507462

508463
class AbsoluteError(IdentityLink, BaseLoss, CyAbsoluteError):
509464
"""Absolute error with identity link, for regression.

0 commit comments

Comments
 (0)