Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c74b8b

Browse filesBrowse files
authored
ENH Optimize dot product order for LogisticRegression for dense matrices (#19571)
* Use multi_dot for Hessian and gradient product. np.linalg.multi_dot quickly chooses the best order for the multiplication of three matrices.
1 parent e3e4a77 commit 0c74b8b
Copy full SHA for 0c74b8b

File tree

2 files changed

+9
-1
lines changed
Filter options

2 files changed

+9
-1
lines changed

‎doc/whats_new/v1.0.rst

Copy file name to clipboardExpand all lines: doc/whats_new/v1.0.rst
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ Changelog
113113
:mod:`sklearn.linear_model`
114114
...........................
115115

116+
- |Efficiency| The implementation of :class:`linear_model.LogisticRegression`
117+
has been optimised for dense matrices when using `solver='newton-cg'` and
118+
`multi_class!='multinomial'`.
119+
:pr:`19571` by :user:`Julien Jerphanion <jjerphan>`.
120+
116121
- |Enhancement| Validate user-supplied gram matrix passed to linear models
117122
via the `precompute` argument. :pr:`19004` by :user:`Adam Midvidy <amidvidy>`.
118123

‎sklearn/linear_model/_logistic.py

Copy file name to clipboardExpand all lines: sklearn/linear_model/_logistic.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ def _logistic_grad_hess(w, X, y, alpha, sample_weight=None):
233233

234234
def Hs(s):
235235
ret = np.empty_like(s)
236-
ret[:n_features] = X.T.dot(dX.dot(s[:n_features]))
236+
if sparse.issparse(X):
237+
ret[:n_features] = X.T.dot(dX.dot(s[:n_features]))
238+
else:
239+
ret[:n_features] = np.linalg.multi_dot([X.T, dX, s[:n_features]])
237240
ret[:n_features] += alpha * s[:n_features]
238241

239242
# For the fit intercept case.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.