Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (25 sloc) 929 Bytes
"""Hyperbolic Cosine Loss"""
import typing
import numpy as np
from h2oaicore.metrics import CustomScorer
class CoshLossScorer(CustomScorer):
_description = "Cosh loss for Regression"
_regression = True
_maximize = False
_perfect_score = 0
_display_name = "COSH"
def score(self,
actual: np.array,
predicted: np.array,
sample_weight: typing.Optional[np.array] = None,
labels: typing.Optional[np.array] = None) -> float:
if sample_weight is None:
sample_weight = np.ones(actual.shape[0])
predicted = predicted.ravel()
good_rows = predicted >= 0
if not good_rows.any():
return 30
delta = predicted[good_rows] - actual[good_rows]
sample_weight = sample_weight[good_rows]
loss = np.log1p(np.cosh(delta))
return np.sum(sample_weight * loss) / np.sum(sample_weight)
You can’t perform that action at this time.