Python源码示例:sklearn.utils.validation.indexable()
示例1
def split(self, y, exogenous=None):
"""Generate indices to split data into training and test sets
Parameters
----------
y : array-like or iterable, shape=(n_samples,)
The time-series array.
exogenous : array-like, shape=[n_obs, n_vars], optional (default=None)
An optional 2-d array of exogenous variables.
Yields
------
train : np.ndarray
The training set indices for the split
test : np.ndarray
The test set indices for the split
"""
y, exog = indexable(y, exogenous)
indices = np.arange(y.shape[0])
for train_index, test_index in self._iter_train_test_masks(y, exog):
train_index = indices[train_index]
test_index = indices[test_index]
yield train_index, test_index
示例2
def to_indexable(*args, **kwargs):
"""Ensure that all args are an indexable type.
Conversion runs lazily for dask objects, immediately otherwise.
Parameters
----------
args : array_like or scalar
allow_scalars : bool, optional
Whether to allow scalars in args. Default is False.
"""
if kwargs.get("allow_scalars", False):
indexable = _maybe_indexable
else:
indexable = _indexable
for x in args:
if x is None or isinstance(x, (da.Array, dd.DataFrame)):
yield x
elif is_dask_collection(x):
yield delayed(indexable, pure=True)(x)
else:
yield indexable(x)
示例3
def _indexable(x):
return indexable(x)[0]
示例4
def _maybe_indexable(x):
return indexable(x)[0] if _is_arraylike(x) else x