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

Function indexable

sklearn/utils/validation.py:484–516  ·  view source on GitHub ↗

Make arrays indexable for cross-validation. Checks consistent length, passes through None, and ensures that everything can be indexed by converting sparse matrices to csr and converting non-iterable objects to arrays. Parameters ---------- *iterables : {lists, dataframes, n

(*iterables)

Source from the content-addressed store, hash-verified

482
483
484def indexable(*iterables):
485 """Make arrays indexable for cross-validation.
486
487 Checks consistent length, passes through None, and ensures that everything
488 can be indexed by converting sparse matrices to csr and converting
489 non-iterable objects to arrays.
490
491 Parameters
492 ----------
493 *iterables : {lists, dataframes, ndarrays, sparse matrices}
494 List of objects to ensure sliceability.
495
496 Returns
497 -------
498 result : list of {ndarray, sparse matrix, dataframe} or None
499 Returns a list containing indexable arrays (i.e. NumPy array,
500 sparse matrix, or dataframe) or `None`.
501
502 Examples
503 --------
504 >>> from sklearn.utils import indexable
505 >>> from scipy.sparse import csr_array
506 >>> import numpy as np
507 >>> iterables = [
508 ... [1, 2, 3], np.array([2, 3, 4]), None, csr_array([[5], [6], [7]])
509 ... ]
510 >>> indexable(*iterables)
511 [[1, 2, 3], array([2, 3, 4]), None, <...Sparse...dtype 'int64'...shape (3, 1)>]
512 """
513
514 result = [_make_indexable(X) for X in iterables]
515 check_consistent_length(*result)
516 return result
517
518
519def _ensure_sparse_format(

Callers 15

fitMethod · 0.90
fitMethod · 0.90
fitMethod · 0.90
cross_validateFunction · 0.90
cross_val_predictFunction · 0.90
permutation_test_scoreFunction · 0.90
learning_curveFunction · 0.90
validation_curveFunction · 0.90
fitMethod · 0.90
fitMethod · 0.90
splitMethod · 0.90
splitMethod · 0.90

Calls 2

_make_indexableFunction · 0.85
check_consistent_lengthFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…