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)
| 482 | |
| 483 | |
| 484 | def 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 | |
| 519 | def _ensure_sparse_format( |
no test coverage detected
searching dependent graphs…