From 77c20fa3b4c606ab819d2c442ec3ae1cd3edc315 Mon Sep 17 00:00:00 2001 From: Calvin McCarter Date: Sun, 22 Dec 2024 22:15:44 -0500 Subject: [PATCH 1/2] Allow NaNs in input X --- ngboost/ngboost.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ngboost/ngboost.py b/ngboost/ngboost.py index c8aa998c..5fddfe10 100644 --- a/ngboost/ngboost.py +++ b/ngboost/ngboost.py @@ -1,4 +1,5 @@ """The NGBoost library""" + # pylint: disable=line-too-long,too-many-instance-attributes,too-many-arguments # pylint: disable=unused-argument,too-many-locals,too-many-branches,too-many-statements # pylint: disable=unused-variable,invalid-unary-operand-type,attribute-defined-outside-init @@ -338,7 +339,12 @@ def partial_fit( raise ValueError("y cannot be None") X, Y = check_X_y( - X, Y, accept_sparse=True, y_numeric=True, multi_output=self.multi_output + X, + Y, + accept_sparse=True, + force_all_finite="allow-nan", + multi_output=self.multi_output, + y_numeric=True, ) self.n_features = X.shape[1] @@ -353,8 +359,9 @@ def partial_fit( X_val, Y_val, accept_sparse=True, - y_numeric=True, + force_all_finite="allow-nan", multi_output=self.multi_output, + y_numeric=True, ) val_params = self.pred_param(X_val) val_loss_list = [] From 0da181d9052d878df0ccc99054e4171aba4f57f9 Mon Sep 17 00:00:00 2001 From: Calvin McCarter Date: Mon, 23 Dec 2024 00:01:29 -0500 Subject: [PATCH 2/2] allow NaNs at inference time --- ngboost/ngboost.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngboost/ngboost.py b/ngboost/ngboost.py index 5fddfe10..1f71123a 100644 --- a/ngboost/ngboost.py +++ b/ngboost/ngboost.py @@ -493,7 +493,7 @@ def pred_dist(self, X, max_iter=None): A NGBoost distribution object """ - X = check_array(X, accept_sparse=True) + X = check_array(X, accept_sparse=True, force_all_finite="allow-nan") params = np.asarray(self.pred_param(X, max_iter)) dist = self.Dist(params.T) @@ -540,7 +540,7 @@ def predict(self, X, max_iter=None): Numpy array of the estimates of Y """ - X = check_array(X, accept_sparse=True) + X = check_array(X, accept_sparse=True, force_all_finite="allow-nan") return self.pred_dist(X, max_iter=max_iter).predict()