Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (21 sloc) 762 Bytes
"""Brier Loss"""
import typing
import numpy as np
from h2oaicore.metrics import CustomScorer
from sklearn.metrics import brier_score_loss
from sklearn.preprocessing import LabelEncoder
class MyBrierLoss(CustomScorer):
_description = "Brier Score Loss"
_binary = True
_maximize = False
_perfect_score = 0
_display_name = "BRIER"
def score(self,
actual: np.array,
predicted: np.array,
sample_weight: typing.Optional[np.array] = None,
labels: typing.Optional[np.array] = None) -> float:
lb = LabelEncoder()
labels = lb.fit_transform(labels)
actual = lb.transform(actual)
return brier_score_loss(actual, predicted, sample_weight, pos_label=labels[1])
You can’t perform that action at this time.