MCPcopy
hub / github.com/scikit-learn/scikit-learn / _num_samples

Function _num_samples

sklearn/utils/validation.py:365–396  ·  view source on GitHub ↗

Return number of samples in array-like x.

(x)

Source from the content-addressed store, hash-verified

363
364
365def _num_samples(x):
366 """Return number of samples in array-like x."""
367 message = "Expected sequence or array-like, got %s" % type(x)
368 if hasattr(x, "fit") and callable(x.fit):
369 # Don't get num_samples from an ensembles length!
370 raise TypeError(message)
371
372 if hasattr(x, "shape") and x.shape is not None:
373 if len(x.shape) == 0:
374 raise TypeError(
375 "Input should have at least 1 dimension i.e. satisfy "
376 f"`len(x.shape) > 0`, got scalar `{x!r}` instead."
377 )
378 # Check that shape is returning an integer or default to len
379 # Dask dataframes may not return numeric shape[0] value
380 if isinstance(x.shape[0], numbers.Integral):
381 return x.shape[0]
382
383 if _nw_into_df_or_series(x):
384 return nw.from_native(x, allow_series=True).shape[0]
385
386 if not hasattr(x, "__len__") and not hasattr(x, "shape"):
387 if hasattr(x, "__array__"):
388 xp, _ = get_namespace(x)
389 x = xp.asarray(x)
390 else:
391 raise TypeError(message)
392
393 try:
394 return len(x)
395 except TypeError as type_error:
396 raise TypeError(message) from type_error
397
398
399def check_memory(memory):

Callers 15

predict_probaMethod · 0.90
predict_probaMethod · 0.90
predictMethod · 0.90
decision_functionMethod · 0.90
predict_probaMethod · 0.90
predictMethod · 0.90
_fit_ovo_binaryFunction · 0.90
fitMethod · 0.90
predictMethod · 0.90
predict_probaMethod · 0.90
predictMethod · 0.90
_fit_and_scoreFunction · 0.90

Calls 2

get_namespaceFunction · 0.90
_nw_into_df_or_seriesFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…