Skip to content

Commit 7ae11ea

Browse files
ENH implement gradient and allow y_i = 0 in Poisson datafit (#253)
Co-authored-by: Badr-MOUFAD <[email protected]>
1 parent 8aea611 commit 7ae11ea

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

skglm/datafits/single_task.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ def params_to_dict(self):
431431
return dict()
432432

433433
def initialize(self, X, y):
434-
if np.any(y <= 0):
434+
if np.any(y < 0):
435435
raise ValueError(
436-
"Target vector `y` should only take positive values " +
436+
"Target vector `y` should only take positive values "
437437
"when fitting a Poisson model.")
438438

439439
def initialize_sparse(self, X_data, X_indptr, X_indices, y):
440-
if np.any(y <= 0):
440+
if np.any(y < 0):
441441
raise ValueError(
442-
"Target vector `y` should only take positive values " +
442+
"Target vector `y` should only take positive values "
443443
"when fitting a Poisson model.")
444444

445445
def raw_grad(self, y, Xw):
@@ -453,6 +453,9 @@ def raw_hessian(self, y, Xw):
453453
def value(self, y, w, Xw):
454454
return np.sum(np.exp(Xw) - y * Xw) / len(y)
455455

456+
def gradient(self, X, y, Xw):
457+
return X.T @ self.raw_grad(y, Xw)
458+
456459
def gradient_scalar(self, X, y, w, Xw, j):
457460
return (X[:, j] @ (np.exp(Xw) - y)) / len(y)
458461

0 commit comments

Comments
 (0)