Python sklearn.utils.validation.indexable() Examples

The following are 4 code examples of sklearn.utils.validation.indexable(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sklearn.utils.validation , or try the search function .
Example #1
Source File: _split.py    From pmdarima with MIT License 6 votes vote down vote up
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 
Example #2
Source File: utils.py    From dask-ml with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #3
Source File: utils.py    From dask-ml with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _indexable(x):
    return indexable(x)[0] 
Example #4
Source File: utils.py    From dask-ml with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _maybe_indexable(x):
    return indexable(x)[0] if _is_arraylike(x) else x