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

Function _unique

sklearn/utils/_encode.py:14–52  ·  view source on GitHub ↗

Helper function to find unique values with support for python objects. Uses pure python method for object dtype, and numpy method for all other dtypes. Parameters ---------- values : ndarray Values to check for unknowns. return_inverse : bool, default=False

(values, *, return_inverse=False, return_counts=False)

Source from the content-addressed store, hash-verified

12
13
14def _unique(values, *, return_inverse=False, return_counts=False):
15 """Helper function to find unique values with support for python objects.
16
17 Uses pure python method for object dtype, and numpy method for
18 all other dtypes.
19
20 Parameters
21 ----------
22 values : ndarray
23 Values to check for unknowns.
24
25 return_inverse : bool, default=False
26 If True, also return the indices of the unique values.
27
28 return_counts : bool, default=False
29 If True, also return the number of times each unique item appears in
30 values.
31
32 Returns
33 -------
34 unique : ndarray
35 The sorted unique values.
36
37 unique_inverse : ndarray
38 The indices to reconstruct the original array from the unique array.
39 Only provided if `return_inverse` is True.
40
41 unique_counts : ndarray
42 The number of times each of the unique values comes up in the original
43 array. Only provided if `return_counts` is True.
44 """
45 if values.dtype == object:
46 return _unique_python(
47 values, return_inverse=return_inverse, return_counts=return_counts
48 )
49 # numerical
50 return _unique_np(
51 values, return_inverse=return_inverse, return_counts=return_counts
52 )
53
54
55def _unique_np(values, return_inverse=False, return_counts=False):

Callers 10

test_encode_utilFunction · 0.90
fitMethod · 0.90
fit_transformMethod · 0.90
_fitMethod · 0.90
top_k_accuracy_scoreFunction · 0.90
from_estimatorMethod · 0.90

Calls 2

_unique_pythonFunction · 0.85
_unique_npFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…