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

Method partial_fit

sklearn/preprocessing/_data.py:1317–1364  ·  view source on GitHub ↗

Online computation of max absolute value of X for later scaling. All of X is processed as a single batch. This is intended for cases when :meth:`fit` is not feasible due to very large number of `n_samples` or because X is read from a continuous stream. Parameters

(self, X, y=None)

Source from the content-addressed store, hash-verified

1315
1316 @_fit_context(prefer_skip_nested_validation=True)
1317 def partial_fit(self, X, y=None):
1318 """Online computation of max absolute value of X for later scaling.
1319
1320 All of X is processed as a single batch. This is intended for cases
1321 when :meth:`fit` is not feasible due to very large number of
1322 `n_samples` or because X is read from a continuous stream.
1323
1324 Parameters
1325 ----------
1326 X : {array-like, sparse matrix} of shape (n_samples, n_features)
1327 The data used to compute the mean and standard deviation
1328 used for later scaling along the features axis.
1329
1330 y : None
1331 Ignored.
1332
1333 Returns
1334 -------
1335 self : object
1336 Fitted scaler.
1337 """
1338 xp, _ = get_namespace(X)
1339
1340 first_pass = not hasattr(self, "n_samples_seen_")
1341 X = validate_data(
1342 self,
1343 X,
1344 reset=first_pass,
1345 accept_sparse=("csr", "csc"),
1346 dtype=_array_api.supported_float_dtypes(xp, device=device(X)),
1347 ensure_all_finite="allow-nan",
1348 )
1349
1350 if sparse.issparse(X):
1351 mins, maxs = min_max_axis(X, axis=0, ignore_nan=True)
1352 max_abs = np.maximum(np.abs(mins), np.abs(maxs))
1353 else:
1354 max_abs = _array_api._nanmax(xp.abs(X), axis=0, xp=xp)
1355
1356 if first_pass:
1357 self.n_samples_seen_ = X.shape[0]
1358 else:
1359 max_abs = xp.maximum(self.max_abs_, max_abs)
1360 self.n_samples_seen_ += X.shape[0]
1361
1362 self.max_abs_ = max_abs
1363 self.scale_ = _handle_zeros_in_scale(max_abs, copy=True)
1364 return self
1365
1366 def transform(self, X):
1367 """Scale the data.

Callers 2

fitMethod · 0.95

Calls 5

get_namespaceFunction · 0.90
validate_dataFunction · 0.90
deviceFunction · 0.90
min_max_axisFunction · 0.90
_handle_zeros_in_scaleFunction · 0.85

Tested by 1