(X=None, y=None, instance_indexes=None, query_type=None, test_ratio=0.3, initial_label_rate=0.05,
          split_count=10, all_class=True, saving_path='.')
return train_idx, test_idx, label_idx, unlabel_idx
Split given data.

    Provide one of X, y or instance_indexes to execute the split.

    Parameters
    ----------
    X: array-like, optional
        Data matrix with [n_samples, n_features]

    y: array-like, optional
        labels of given data [n_samples, n_labels] or [n_samples]

    instance_indexes: list, optional (default=None)
        List contains instances' names, used for image datasets,
        or provide index list instead of data matrix.
        Must provide one of [instance_names, X, y]

    query_type: str, optional (default='AllLabels')
        Query type. Should be one of:
        'AllLabels': Query all labels of an instance
        'PartLabels': Query part of labels of an instance (Only available in multi-label setting)
        'Features': Query unlab_features of instances

    test_ratio: float, optional (default=0.3)
        Ratio of test set

    initial_label_rate: float, optional (default=0.05)
        Ratio of initial label set
        e.g. Initial_labelset*(1-test_ratio)*n_samples

    split_count: int, optional (default=10)
        Random split data _split_count times

    all_class: bool, optional (default=True)
        Whether each split will contain at least one instance for each class.
        If False, a totally random split will be performed.

    saving_path: str, optional (default='.')
        Giving None to disable saving.

    Returns
    -------
    train_idx: list
        index of training set, shape like [n_split_count, n_training_indexes]

    test_idx: list
        index of testing set, shape like [n_split_count, n_testing_indexes]

    label_idx: list
        index of labeling set, shape like [n_split_count, n_labeling_indexes]

    unlabel_idx: list
        index of unlabeling set, shape like [n_split_count, n_unlabeling_indexes]
Split given data.
Split given data .
def split(X=None, y=None, instance_indexes=None, query_type=None, test_ratio=0.3, initial_label_rate=0.05,
          split_count=10, all_class=True, saving_path='.'):
    """Split given data.

    Provide one of X, y or instance_indexes to execute the split.

    Parameters
    ----------
    X: array-like, optional
        Data matrix with [n_samples, n_features]

    y: array-like, optional
        labels of given data [n_samples, n_labels] or [n_samples]

    instance_indexes: list, optional (default=None)
        List contains instances' names, used for image datasets,
        or provide index list instead of data matrix.
        Must provide one of [instance_names, X, y]

    query_type: str, optional (default='AllLabels')
        Query type. Should be one of:
        'AllLabels': Query all labels of an instance
        'PartLabels': Query part of labels of an instance (Only available in multi-label setting)
        'Features': Query unlab_features of instances

    test_ratio: float, optional (default=0.3)
        Ratio of test set

    initial_label_rate: float, optional (default=0.05)
        Ratio of initial label set
        e.g. Initial_labelset*(1-test_ratio)*n_samples

    split_count: int, optional (default=10)
        Random split data _split_count times

    all_class: bool, optional (default=True)
        Whether each split will contain at least one instance for each class.
        If False, a totally random split will be performed.

    saving_path: str, optional (default='.')
        Giving None to disable saving.

    Returns
    -------
    train_idx: list
        index of training set, shape like [n_split_count, n_training_indexes]

    test_idx: list
        index of testing set, shape like [n_split_count, n_testing_indexes]

    label_idx: list
        index of labeling set, shape like [n_split_count, n_labeling_indexes]

    unlabel_idx: list
        index of unlabeling set, shape like [n_split_count, n_unlabeling_indexes]
    """
    # check parameters
    if X is None and y is None and instance_indexes is None:
        raise Exception("Must provide one of X, y or instance_indexes.")
    len_of_parameters = [len(X) if X is not None else None, len(y) if y is not None else None,
                         len(instance_indexes) if instance_indexes is not None else None]
    number_of_instance = np.unique([i for i in len_of_parameters if i is not None])
    if len(number_of_instance) > 1:
        raise ValueError("Different length of instances and _labels found.")
    else:
        number_of_instance = number_of_instance[0]
    if query_type is None:
        query_type = 'AllLabels'
    else:
        if not check_query_type(query_type):
            raise NotImplementedError("Query type %s is not implemented." % type)
    if instance_indexes is not None:
        if not isinstance(instance_indexes, (list, np.ndarray)):
            raise TypeError("A list or np.ndarray object is expected, but received: %s" % str(type(instance_indexes)))
        instance_indexes = np.array(instance_indexes)
    else:
        instance_indexes = np.arange(number_of_instance)

    # split
    train_idx = []
    test_idx = []
    label_idx = []
    unlabel_idx = []
    for i in range(split_count):
        if (not all_class) or y is None:
            rp = randperm(number_of_instance - 1)
            cutpoint = int(round((1 - test_ratio) * len(rp)))
            tp_train = instance_indexes[rp[0:cutpoint]]
            train_idx.append(tp_train)
            test_idx.append(instance_indexes[rp[cutpoint:]])
            cutpoint = int(round(initial_label_rate * len(tp_train)))
            if cutpoint <= 1:
                cutpoint = 1
            label_idx.append(tp_train[0:cutpoint])
            unlabel_idx.append(tp_train[cutpoint:])
        else:
            if y is None:
                raise Exception("y must be provided when all_class flag is True.")
            y = check_array(y, ensure_2d=False, dtype=None)
            if y.ndim == 1:
                label_num = len(np.unique(y))
            else:
                label_num = y.shape[1]
            if round((1 - test_ratio) * initial_label_rate * number_of_instance) < label_num:
                raise ValueError(
                    "The initial rate is too small to guarantee that each "
                    "split will contain at least one instance for each class.")

            # check validaty
            while 1:
                rp = randperm(number_of_instance - 1)
                cutpoint = int(round((1 - test_ratio) * len(rp)))
                tp_train = instance_indexes[rp[0:cutpoint]]
                cutpointlabel = int(round(initial_label_rate * len(tp_train)))
                if cutpointlabel <= 1:
                    cutpointlabel = 1
                label_id = tp_train[0:cutpointlabel]
                if y.ndim == 1:
                    if len(np.unique(y[label_id])) == label_num:
                        break
                else:
                    temp = np.sum(y[label_id], axis=0)
                    if not np.any(temp == 0):
                        break
            train_idx.append(tp_train)
            test_idx.append(instance_indexes[rp[cutpoint:]])
            label_idx.append(tp_train[0:cutpointlabel])
            unlabel_idx.append(tp_train[cutpointlabel:])

    split_save(train_idx=train_idx, test_idx=test_idx, label_idx=label_idx,
               unlabel_idx=unlabel_idx, path=saving_path)
    return train_idx, test_idx, label_idx, unlabel_idx
def split ( X = None , y = None , instance_indexes = None , query_type = None , test_ratio = 0.3 , initial_label_rate = 0.05 , split_count = 10 , all_class = True , saving_path = '.' ) : # check parameters if X is None and y is None and instance_indexes is None : raise Exception ( "Must provide one of X, y or instance_indexes." ) len_of_parameters = [ len ( X ) if X is not None else None , len ( y ) if y is not None else None , len ( instance_indexes ) if instance_indexes is not None else None ] number_of_instance = np . unique ( [ i for i in len_of_parameters if i is not None ] ) if len ( number_of_instance ) > 1 : raise ValueError ( "Different length of instances and _labels found." ) else : number_of_instance = number_of_instance [ 0 ] if query_type is None : query_type = 'AllLabels' else : if not check_query_type ( query_type ) : raise NotImplementedError ( "Query type %s is not implemented." % type ) if instance_indexes is not None : if not isinstance ( instance_indexes , ( list , np . ndarray ) ) : raise TypeError ( "A list or np.ndarray object is expected, but received: %s" % str ( type ( instance_indexes ) ) ) instance_indexes = np . array ( instance_indexes ) else : instance_indexes = np . arange ( number_of_instance ) # split train_idx = [ ] test_idx = [ ] label_idx = [ ] unlabel_idx = [ ] for i in range ( split_count ) : if ( not all_class ) or y is None : rp = randperm ( number_of_instance - 1 ) cutpoint = int ( round ( ( 1 - test_ratio ) * len ( rp ) ) ) tp_train = instance_indexes [ rp [ 0 : cutpoint ] ] train_idx . append ( tp_train ) test_idx . append ( instance_indexes [ rp [ cutpoint : ] ] ) cutpoint = int ( round ( initial_label_rate * len ( tp_train ) ) ) if cutpoint <= 1 : cutpoint = 1 label_idx . append ( tp_train [ 0 : cutpoint ] ) unlabel_idx . append ( tp_train [ cutpoint : ] ) else : if y is None : raise Exception ( "y must be provided when all_class flag is True." ) y = check_array ( y , ensure_2d = False , dtype = None ) if y . ndim == 1 : label_num = len ( np . unique ( y ) ) else : label_num = y . shape [ 1 ] if round ( ( 1 - test_ratio ) * initial_label_rate * number_of_instance ) < label_num : raise ValueError ( "The initial rate is too small to guarantee that each " "split will contain at least one instance for each class." ) # check validaty while 1 : rp = randperm ( number_of_instance - 1 ) cutpoint = int ( round ( ( 1 - test_ratio ) * len ( rp ) ) ) tp_train = instance_indexes [ rp [ 0 : cutpoint ] ] cutpointlabel = int ( round ( initial_label_rate * len ( tp_train ) ) ) if cutpointlabel <= 1 : cutpointlabel = 1 label_id = tp_train [ 0 : cutpointlabel ] if y . ndim == 1 : if len ( np . unique ( y [ label_id ] ) ) == label_num : break else : temp = np . sum ( y [ label_id ] , axis = 0 ) if not np . any ( temp == 0 ) : break train_idx . append ( tp_train ) test_idx . append ( instance_indexes [ rp [ cutpoint : ] ] ) label_idx . append ( tp_train [ 0 : cutpointlabel ] ) unlabel_idx . append ( tp_train [ cutpointlabel : ] ) split_save ( train_idx = train_idx , test_idx = test_idx , label_idx = label_idx , unlabel_idx = unlabel_idx , path = saving_path ) return train_idx , test_idx , label_idx , unlabel_idx