Skip to content

[MRG] Avoid uncessary copies in sklearn.preprocessing - #13987

Merged
thomasjpfan merged 3 commits into
scikit-learn:masterfrom
rth:avoid-copy-preprocessing
Jun 1, 2019
Merged

thomasjpfan merged 3 commits into
scikit-learn:masterfrom
rth:avoid-copy-preprocessing

Conversation

@rth

@rth rth commented May 30, 2019

Copy link
Copy Markdown
Member

Partially addresses #13986

This removes the copy=True in the fit method of StandardScaler, MinMaxScaler, MaxAbsScaler, RobustScaler where it is typically not necessary to compute the scaling factors.

In practice, this makes StandardScaler().fit_transform 10%-20% faster on the few examples I have tried.

If that copy was necessary and this mistakenly removed it check_transformer_general(.., readonly_memmap=True) would fail in common tests.

@NicolasHug NicolasHug left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Looks like in these specific cases inplace would have been a more descriptive parameter name than copy, and might have prevented this.

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan

Copy link
Copy Markdown
Member

Does this need a whats_new entry as an enhancement or a bug fix?

@rth

rth commented May 31, 2019

Copy link
Copy Markdown
Member Author

Thanks for the reviews! Added a what's new.

@thomasjpfan

Copy link
Copy Markdown
Member

QuantileTransformer has a _check_inputs that copies during fit and transform. What you think about adding copy parameter to _check_inputs and setting it to false during fit and self.copy during transform?

@thomasjpfan
thomasjpfan merged commit 9661a64 into scikit-learn:master Jun 1, 2019
@thomasjpfan

Copy link
Copy Markdown
Member

Thank you @rth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants