Skip to content

Commit 79f949e

Browse files
committed
Merge branch 'sgd-fortran-layout'
2 parents 2da6464 + 4ddf69e commit 79f949e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

doc/whats_new.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Changelog
3232
solution was retained instead of the best solution.
3333

3434
- Minor refactoring in :ref:`sgd` module; consolidated dense and sparse
35-
predict methods.
35+
predict methods; Enhanced test time performance by converting model
36+
paramters to fortran-style arrays after fitting (only multi-class).
3637

3738
- Adjusted Mutual Information metric added as
3839
:func:`sklearn.metrics.adjusted_mutual_info_score` by Robert Layton.

sklearn/linear_model/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,13 @@ def _validate_sample_weight(self, sample_weight, n_samples):
249249
return sample_weight
250250

251251
def _set_coef(self, coef_):
252-
"""Make sure that coef_ is 2d. """
253-
self.coef_ = array2d(coef_)
252+
"""Make sure that coef_ is fortran-style and 2d.
253+
254+
Fortran-style memory layout is needed to ensure that computing
255+
the dot product between input ``X`` and ``coef_`` does not trigger
256+
a memory copy.
257+
"""
258+
self.coef_ = np.asfortranarray(array2d(coef_))
254259

255260
def _allocate_parameter_mem(self, n_classes, n_features, coef_init=None,
256261
intercept_init=None):

sklearn/linear_model/stochastic_gradient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def _fit_multiclass(self, X, y, sample_weight):
183183
self.coef_[i] = coef
184184
self.intercept_[i] = intercept
185185

186+
self._set_coef(self.coef_)
187+
186188

187189
def _train_ova_classifier(i, c, X, y, coef_, intercept_, loss_function,
188190
penalty_type, alpha, rho, n_iter, fit_intercept,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy