(X, y)
return csr_matrix((data, indices, indptr), shape=(n_rows, X.shape[1]), dtype=X.dtype), y_
Parameters
    ----------
    X : (sparse) array-like, shape = [n_samples, n_features]
        Data.

    y : list-of-lists - [n_samples]
        For each sample, y maintains list of labels this sample should be used for in training.

    Returns
    -------
    X_, y_
        Transformed by 'flattening' out y parameter and duplicating corresponding rows in X
Parameters
    ----------
    X : (sparse) array-like, shape = [n_samples, n_features]
        Data.
Parameters ---------- X : ( sparse ) array - like shape = [ n_samples n_features ] Data .
def apply_rollup_Xy(X, y):
    """
    Parameters
    ----------
    X : (sparse) array-like, shape = [n_samples, n_features]
        Data.

    y : list-of-lists - [n_samples]
        For each sample, y maintains list of labels this sample should be used for in training.

    Returns
    -------
    X_, y_
        Transformed by 'flattening' out y parameter and duplicating corresponding rows in X

    """
    # Compute number of rows we will have after transformation
    n_rows = sum(len(labelset) for labelset in y)

    if n_rows == X.shape[0]:
        # No expansion needed
        return X, flatten_list(y)

    if not isinstance(X, csr_matrix):
        # Performance improvements require csr matrix
        X = csr_matrix(X)

    indptr = np.zeros((n_rows+1), dtype=np.int32)
    indices = []
    data = []

    indices_count = 0
    offset = 0

    # Our goal is to expand the equal labelsets into their own row within X
    # We do this by repeating each row exactly "labelset" times
    for i, labelset in enumerate(y):
        labelset_sz = len(labelset)
        for j in range(labelset_sz):
            indptr[offset+j] = indices_count

            indices.append(X.indices[X.indptr[i]:X.indptr[i+1]])
            data.append(X.data[X.indptr[i]:X.indptr[i+1]])

            indices_count += len(X.data[X.indptr[i]:X.indptr[i+1]])

        offset += labelset_sz

    indptr[-1] = indices_count

    indices = np.concatenate(indices)
    data = np.concatenate(data)

    y_ = flatten_list(y)
    return csr_matrix((data, indices, indptr), shape=(n_rows, X.shape[1]), dtype=X.dtype), y_
def apply_rollup_Xy ( X , y ) : # Compute number of rows we will have after transformation n_rows = sum ( len ( labelset ) for labelset in y ) if n_rows == X . shape [ 0 ] : # No expansion needed return X , flatten_list ( y ) if not isinstance ( X , csr_matrix ) : # Performance improvements require csr matrix X = csr_matrix ( X ) indptr = np . zeros ( ( n_rows + 1 ) , dtype = np . int32 ) indices = [ ] data = [ ] indices_count = 0 offset = 0 # Our goal is to expand the equal labelsets into their own row within X # We do this by repeating each row exactly "labelset" times for i , labelset in enumerate ( y ) : labelset_sz = len ( labelset ) for j in range ( labelset_sz ) : indptr [ offset + j ] = indices_count indices . append ( X . indices [ X . indptr [ i ] : X . indptr [ i + 1 ] ] ) data . append ( X . data [ X . indptr [ i ] : X . indptr [ i + 1 ] ] ) indices_count += len ( X . data [ X . indptr [ i ] : X . indptr [ i + 1 ] ] ) offset += labelset_sz indptr [ - 1 ] = indices_count indices = np . concatenate ( indices ) data = np . concatenate ( data ) y_ = flatten_list ( y ) return csr_matrix ( ( data , indices , indptr ) , shape = ( n_rows , X . shape [ 1 ] ) , dtype = X . dtype ) , y_