diff --git a/lightgbmlss/distributions/distribution_utils.py b/lightgbmlss/distributions/distribution_utils.py index 96a4173..a8e90ee 100644 --- a/lightgbmlss/distributions/distribution_utils.py +++ b/lightgbmlss/distributions/distribution_utils.py @@ -127,6 +127,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b """ # Target target = torch.tensor(data.get_label().reshape(-1, 1)) + n_obs = target.shape[0] # Start values (needed to replace NaNs in predt) start_values = data.get_init_score().reshape(-1, self.n_dist_param)[0, :].tolist() @@ -135,7 +136,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b is_higher_better = False _, loss = self.get_params_loss(predt, target, start_values, requires_grad=False) - return self.loss_fn, loss, is_higher_better + return self.loss_fn, loss / n_obs, is_higher_better def loss_fn_start_values(self, params: torch.Tensor, diff --git a/lightgbmlss/distributions/flow_utils.py b/lightgbmlss/distributions/flow_utils.py index b63d0a9..7b54272 100644 --- a/lightgbmlss/distributions/flow_utils.py +++ b/lightgbmlss/distributions/flow_utils.py @@ -143,6 +143,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b """ # Target target = torch.tensor(data.get_label().reshape(-1, 1)) + n_obs = target.shape[0] # Start values (needed to replace NaNs in predt) start_values = data.get_init_score().reshape(-1, self.n_dist_param)[0, :].tolist() @@ -151,7 +152,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b is_higher_better = False _, loss = self.get_params_loss(predt, target, start_values) - return self.loss_fn, loss.detach(), is_higher_better + return self.loss_fn, loss.detach() / n_obs, is_higher_better def calculate_start_values(self, target: np.ndarray, diff --git a/lightgbmlss/distributions/mixture_distribution_utils.py b/lightgbmlss/distributions/mixture_distribution_utils.py index 9d49360..ee26498 100644 --- a/lightgbmlss/distributions/mixture_distribution_utils.py +++ b/lightgbmlss/distributions/mixture_distribution_utils.py @@ -170,6 +170,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b """ # Target target = torch.tensor(data.get_label().reshape(-1, 1), dtype=torch.float32) + n_obs = target.shape[0] # Start values (needed to replace NaNs in predt) start_values = data.get_init_score().reshape(-1, self.n_dist_param)[0, :].tolist() @@ -178,7 +179,7 @@ def metric_fn(self, predt: np.ndarray, data: lgb.Dataset) -> Tuple[str, float, b is_higher_better = False _, loss = self.get_params_loss(predt, target.flatten(), start_values, requires_grad=False) - return self.loss_fn, loss, is_higher_better + return self.loss_fn, loss / n_obs, is_higher_better def create_mixture_distribution(self, params: List[torch.Tensor],