MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / transform

Method transform

sklearn/preprocessing/_data.py:1092–1135  ·  view source on GitHub ↗

Perform standardization by centering and scaling. Parameters ---------- X : {array-like, sparse matrix of shape (n_samples, n_features) The data used to scale along the features axis. copy : bool, default=None Copy the input X or not.

(self, X, copy=None)

Source from the content-addressed store, hash-verified

1090 return self
1091
1092 def transform(self, X, copy=None):
1093 """Perform standardization by centering and scaling.
1094
1095 Parameters
1096 ----------
1097 X : {array-like, sparse matrix of shape (n_samples, n_features)
1098 The data used to scale along the features axis.
1099 copy : bool, default=None
1100 Copy the input X or not.
1101
1102 Returns
1103 -------
1104 X_tr : {ndarray, sparse matrix} of shape (n_samples, n_features)
1105 Transformed array.
1106 """
1107 xp, _, X_device = get_namespace_and_device(X)
1108 check_is_fitted(self)
1109
1110 copy = copy if copy is not None else self.copy
1111 X = validate_data(
1112 self,
1113 X,
1114 reset=False,
1115 accept_sparse="csr",
1116 copy=copy,
1117 dtype=supported_float_dtypes(xp, X_device),
1118 force_writeable=True,
1119 ensure_all_finite="allow-nan",
1120 )
1121
1122 if sparse.issparse(X):
1123 if self.with_mean:
1124 raise ValueError(
1125 "Cannot center sparse matrices: pass `with_mean=False` "
1126 "instead. See docstring for motivation and alternatives."
1127 )
1128 if self.scale_ is not None:
1129 inplace_column_scale(X, 1 / self.scale_)
1130 else:
1131 if self.with_mean:
1132 X -= xp.astype(self.mean_, X.dtype)
1133 if self.with_std:
1134 X /= xp.astype(self.scale_, X.dtype)
1135 return X
1136
1137 def inverse_transform(self, X, copy=None):
1138 """Scale back the data to the original representation.

Calls 5

get_namespace_and_deviceFunction · 0.90
check_is_fittedFunction · 0.90
validate_dataFunction · 0.90
supported_float_dtypesFunction · 0.90
inplace_column_scaleFunction · 0.90