Skip to content

DOC Document copy parameter and add link to the glossary entry #30307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,14 @@ functions or non-estimator constructors.
The ``class_weight`` parameter is validated and interpreted with
:func:`utils.class_weight.compute_class_weight`.

``copy``
This parameter is used to specify the nature of the input operated
during computation. If False, try to avoid a copy and modify the input
in place.
This is not guaranteed to always work in place. If the input is not an
array of floating values or encoded as a CSR matrix, a new copy will
always be made, even if `copy=False`.

``cv``
Determines a cross validation splitting strategy, as used in
cross-validation based routines. ``cv`` is also available in estimators
Expand Down
3 changes: 2 additions & 1 deletion sklearn/cluster/_affinity_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def affinity_propagation(
copy : bool, default=True
If copy is False, the affinity matrix is modified inplace by the
algorithm, for memory efficiency.
See the :term:`Glossary <copy>`.

verbose : bool, default=False
The verbosity level.
Expand Down Expand Up @@ -331,7 +332,7 @@ class AffinityPropagation(ClusterMixin, BaseEstimator):
of estimated clusters that stops the convergence.

copy : bool, default=True
Make a copy of input data.
Make a copy of input data. See the :term:`Glossary <copy>`.
Copy link
Contributor

@StefanieSenger StefanieSenger Nov 19, 2024

Choose a reason for hiding this comment

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

Suggested change
Make a copy of input data. See the :term:`Glossary <copy>`.
Make a :term:`copy` of input data.

Rather like this?


preference : array-like of shape (n_samples,) or float, default=None
Preferences for each point - points with larger values of
Expand Down
1 change: 1 addition & 0 deletions sklearn/cluster/_birch.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class Birch(
copy : bool, default=True
Whether or not to make a copy of the given data. If set to False,
the initial data will be overwritten.
See the :term:`Glossary <copy>`.

.. deprecated:: 1.6
`copy` was deprecated in 1.6 and will be removed in 1.8. It has no effect
Expand Down
1 change: 1 addition & 0 deletions sklearn/cluster/_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def discretize(

copy : bool, default=True
Whether to copy vectors, or perform in-place normalization.
See the :term:`Glossary <copy>`.

max_svd_restarts : int, default=30
Maximum number of attempts to restart SVD if convergence fails
Expand Down
6 changes: 6 additions & 0 deletions sklearn/cross_decomposition/_pls.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def transform(self, X, y=None, Y=None, copy=True):

copy : bool, default=True
Whether to copy `X` and `Y`, or perform in-place normalization.
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down Expand Up @@ -515,6 +516,7 @@ def predict(self, X, copy=True):

copy : bool, default=True
Whether to copy `X` and `Y`, or perform in-place normalization.
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down Expand Up @@ -595,6 +597,7 @@ class PLSRegression(_PLS):
Whether to copy `X` and `Y` in :term:`fit` before applying centering,
and potentially scaling. If `False`, these operations will be done
inplace, modifying both arrays.
See the :term:`Glossary <copy>`.

Attributes
----------
Expand Down Expand Up @@ -760,6 +763,7 @@ class PLSCanonical(_PLS):
Whether to copy `X` and `Y` in fit before applying centering, and
potentially scaling. If False, these operations will be done inplace,
modifying both arrays.
See the :term:`Glossary <copy>`.

Attributes
----------
Expand Down Expand Up @@ -885,6 +889,7 @@ class CCA(_PLS):
Whether to copy `X` and `Y` in fit before applying centering, and
potentially scaling. If False, these operations will be done inplace,
modifying both arrays.
See the :term:`Glossary <copy>`.

Attributes
----------
Expand Down Expand Up @@ -991,6 +996,7 @@ class PLSSVD(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
Whether to copy `X` and `Y` in fit before applying centering, and
potentially scaling. If `False`, these operations will be done inplace,
modifying both arrays.
See the :term:`Glossary <copy>`.

Attributes
----------
Expand Down
1 change: 1 addition & 0 deletions sklearn/decomposition/_factor_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class FactorAnalysis(ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEsti
copy : bool, default=True
Whether to make a copy of X. If ``False``, the input X gets overwritten
during fitting.
See the :term:`Glossary <copy>`.

max_iter : int, default=1000
Maximum number of iterations.
Expand Down
2 changes: 2 additions & 0 deletions sklearn/decomposition/_fastica.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ def transform(self, X, copy=True):

copy : bool, default=True
If False, data passed to fit can be overwritten. Defaults to True.
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down Expand Up @@ -778,6 +779,7 @@ def inverse_transform(self, X, copy=True):
and `n_components` is the number of components.
copy : bool, default=True
If False, data passed to fit are overwritten. Defaults to True.
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down
1 change: 1 addition & 0 deletions sklearn/decomposition/_incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class IncrementalPCA(_BasePCA):
copy : bool, default=True
If False, X will be overwritten. ``copy=False`` can be used to
save memory but is unsafe for general use.
See the :term:`Glossary <copy>`.

batch_size : int, default=None
The number of samples to use for each batch. Only used when calling
Expand Down
1 change: 1 addition & 0 deletions sklearn/decomposition/_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class PCA(_BasePCA):
If False, data passed to fit are overwritten and running
fit(X).transform(X) will not yield the expected results,
use fit_transform(X) instead.
See the :term:`Glossary <copy>`.

whiten : bool, default=False
When True (False by default) the `components_` vectors are multiplied
Expand Down
1 change: 1 addition & 0 deletions sklearn/feature_extraction/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ def transform(self, X, copy=True):
copy : bool, default=True
Whether to copy X and operate on the copy or perform in-place
operations. `copy=False` will only be effective with CSR sparse matrix.
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down
3 changes: 3 additions & 0 deletions sklearn/feature_selection/_mutual_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def _estimate_mi(
copy : bool, default=True
Whether to make a copy of the given data. If set to False, the initial
data will be overwritten.
See the :term:`Glossary <copy>`.

random_state : int, RandomState instance or None, default=None
Determines random number generation for adding small noise to
Expand Down Expand Up @@ -381,6 +382,7 @@ def mutual_info_regression(
copy : bool, default=True
Whether to make a copy of the given data. If set to False, the initial
data will be overwritten.
See the :term:`Glossary <copy>`.

random_state : int, RandomState instance or None, default=None
Determines random number generation for adding small noise to
Expand Down Expand Up @@ -509,6 +511,7 @@ def mutual_info_classif(
copy : bool, default=True
Whether to make a copy of the given data. If set to False, the initial
data will be overwritten.
See the :term:`Glossary <copy>`.

random_state : int, RandomState instance or None, default=None
Determines random number generation for adding small noise to
Expand Down
1 change: 1 addition & 0 deletions sklearn/impute/_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class KNNImputer(_BaseImputer):
copy : bool, default=True
If True, a copy of X will be created. If False, imputation will
be done in-place whenever possible.
See the :term:`Glossary <copy>`.

add_indicator : bool, default=False
If True, a :class:`MissingIndicator` transform will stack onto the
Expand Down
1 change: 1 addition & 0 deletions sklearn/linear_model/_omp.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ def _omp_path_residues(
copy : bool, default=True
Whether X_train, X_test, y_train and y_test should be copied. If
False, they may be overwritten.
See the :term:`Glossary <copy>`.

fit_intercept : bool, default=True
Whether to calculate the intercept for this model. If set
Expand Down
1 change: 1 addition & 0 deletions sklearn/metrics/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ def nan_euclidean_distances(

copy : bool, default=True
Make and use a deep copy of X and Y (if Y exists).
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion sklearn/utils/extmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def softmax(X, copy=True):
Argument to the logistic function.

copy : bool, default=True
Copy X or not.
Copy X or not. See the :term:`Glossary <copy>`.

Returns
-------
Expand Down Expand Up @@ -1258,6 +1258,7 @@ def safe_sqr(X, *, copy=True):
copy : bool, default=True
Whether to create a copy of X and operate on it or to perform
inplace computation (default behaviour).
See the :term:`Glossary <copy>`.

Returns
-------
Expand Down
1 change: 1 addition & 0 deletions sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def as_float_array(
copy : bool, default=True
If True, a copy of X will be created. If False, a copy may still be
returned if X's dtype is not a floating point type.
See the :term:`Glossary <copy>`.

force_all_finite : bool or 'allow-nan', default=True
Whether to raise an error on np.inf, np.nan, pd.NA in X. The
Expand Down