(self, y, X=None, instance_indexes=None,
                 query_type='AllLabels', saving_path=None, **kwargs)
index_len: int, length of indexes.
        y: 2d array, the label matrix of whole dataset.
        target_type: str, the type of target.
        label_space: list, the label space.
        label_num: int, The number of unique labels.
        instance_flag: bool, Whether passed instances when initializing.
        X: 2d array, The feature matrix of the whole dataset.
        indexes: list, The indexes of each instances, should have the same length of the feature and label matrix.
        query_type: str, The query type of this active learning project.
        split: bool, whether split the data.
        split_count: int, the number of split times.
        train_idx: list, a list split_count lists which include the indexes of training set.
        test_idx: list, a list split_count lists which include the indexes of testing set.
        label_idx: list, a list split_count lists which include the indexes of labeled set. (A subset of training set)
        unlabel_idx: list, a list split_count lists which include the indexes of unlabeled set. (A subset of training set)
        saving_path: str, saving path.
        saving_dir: str, saving dir.
index_len: int, length of indexes.
        y: 2d array, the label matrix of whole dataset.
        target_type: str, the type of target.
        label_space: list, the label space.
        label_num: int, The number of unique labels.
        instance_flag: bool, Whether passed instances when initializing.
        X: 2d array, The feature matrix of the whole dataset.
        indexes: list, The indexes of each instances, should have the same length of the feature and label matrix.
        query_type: str, The query type of this active learning project.
        split: bool, whether split the data.
        split_count: int, the number of split times.
        train_idx: list, a list split_count lists which include the indexes of training set.
        test_idx: list, a list split_count lists which include the indexes of testing set.
        label_idx: list, a list split_count lists which include the indexes of labeled set. (A subset of training set)
        unlabel_idx: list, a list split_count lists which include the indexes of unlabeled set. (A subset of training set)
        saving_path: str, saving path.
        saving_dir: str, saving dir.
index_len : int length of indexes . y : 2d array the label matrix of whole dataset . target_type : str the type of target . label_space : list the label space . label_num : int The number of unique labels . instance_flag : bool Whether passed instances when initializing . X : 2d array The feature matrix of the whole dataset . indexes : list The indexes of each instances should have the same length of the feature and label matrix . query_type : str The query type of this active learning project . split : bool whether split the data . split_count : int the number of split times . train_idx : list a list split_count lists which include the indexes of training set . test_idx : list a list split_count lists which include the indexes of testing set . label_idx : list a list split_count lists which include the indexes of labeled set . ( A subset of training set ) unlabel_idx : list a list split_count lists which include the indexes of unlabeled set . ( A subset of training set ) saving_path : str saving path . saving_dir : str saving dir .
def __init__(self, y, X=None, instance_indexes=None,
                 query_type='AllLabels', saving_path=None, **kwargs):
        """
        index_len: int, length of indexes.
        y: 2d array, the label matrix of whole dataset.
        target_type: str, the type of target.
        label_space: list, the label space.
        label_num: int, The number of unique labels.
        instance_flag: bool, Whether passed instances when initializing.
        X: 2d array, The feature matrix of the whole dataset.
        indexes: list, The indexes of each instances, should have the same length of the feature and label matrix.
        query_type: str, The query type of this active learning project.
        split: bool, whether split the data.
        split_count: int, the number of split times.
        train_idx: list, a list split_count lists which include the indexes of training set.
        test_idx: list, a list split_count lists which include the indexes of testing set.
        label_idx: list, a list split_count lists which include the indexes of labeled set. (A subset of training set)
        unlabel_idx: list, a list split_count lists which include the indexes of unlabeled set. (A subset of training set)
        saving_path: str, saving path.
        saving_dir: str, saving dir.
        """
        self._index_len = None
        # check and record parameters
        self._y = check_array(y, ensure_2d=False, dtype=None)
        if self._y.ndim == 2:
            if self._y.shape[0] == 1 or self._y.shape[1] == 1:
                self._y = self._y.flatten()
        ytype = type_of_target(self._y)
        if len(self._y.shape) == 2:
            self._target_type = 'multilabel'
        else:
            self._target_type = ytype
        self._index_len = len(self._y)
        if len(self._y.shape) == 1:
            self._label_space = unique_labels(self._y)
        elif len(self._y.shape) == 2:
            self._label_space = list(range(self._y.shape[1]))
        else:
            raise ValueError("Label matrix should be 1d or 2d array.")
        self._label_num = len(self._label_space)

        self._instance_flag = False
        if X is not None:
            self._instance_flag = True
            self._X = check_array(X, accept_sparse='csr', ensure_2d=True, order='C')
            n_samples = self._X.shape[0]
            if n_samples != self._index_len:
                raise ValueError("Different length of instances and labels found.")
            else:
                self._index_len = n_samples

        if instance_indexes is None:
            self._indexes = [i for i in range(self._index_len)]
        else:
            if len(instance_indexes) != self._index_len:
                raise ValueError("Length of given instance_indexes do not accord the data set.")
            self._indexes = copy.copy(instance_indexes)

        if check_query_type(query_type):
            self.query_type = query_type
            if self.query_type == 'Features' and not self._instance_flag:
                raise Exception("In feature querying, feature matrix must be given.")
        else:
            raise NotImplementedError("Query type %s is not implemented." % type)

        self._split = False
        train_idx = kwargs.pop('train_idx', None)
        test_idx = kwargs.pop('test_idx', None)
        label_idx = kwargs.pop('label_idx', None)
        unlabel_idx = kwargs.pop('unlabel_idx', None)
        if train_idx is not None and test_idx is not None and label_idx is not None and unlabel_idx is not None:
            if not (len(train_idx) == len(test_idx) == len(label_idx) == len(unlabel_idx)):
                raise ValueError("train_idx, test_idx, label_idx, unlabel_idx "
                                 "should have the same split count (length)")
            self._split = True
            self.train_idx = train_idx
            self.test_idx = test_idx
            self.label_idx = label_idx
            self.unlabel_idx = unlabel_idx
            self.split_count = len(train_idx)

        self._saving_path = saving_path
        self._saving_dir = None
        if saving_path is not None:
            if not isinstance(self._saving_path, str):
                raise TypeError("A string is expected, but received: %s" % str(type(self._saving_path)))
            self._saving_path = os.path.abspath(saving_path)
            if os.path.isdir(self._saving_path):
                self._saving_dir = self._saving_path
                if os.path.exists(os.path.join(saving_path, 'al_settings.pkl')):
                    warnings.warn("An existed Toolbox file is detected, load the existed one in case of overwriting. "
                                  "(Delete the old file to create a new Toolbox object)", category=UserWarning)
                    with open(os.path.join(saving_path, 'al_settings.pkl'), 'rb') as f:
                        existed_toolbox = pickle.load(f)
                        for ke in existed_toolbox.__dict__.keys():
                            setattr(self, ke, getattr(existed_toolbox, ke))
                        return
            else:
                self._saving_dir = os.path.split(self._saving_path)[0]  # if a directory, a dir and None will return.
                if os.path.exists(saving_path):
                    with open(os.path.abspath(saving_path), 'rb') as f:
                        existed_toolbox = pickle.load(f)
                        for ke in existed_toolbox.__dict__.keys():
                            setattr(self, ke, getattr(existed_toolbox, ke))
                        return
            self.save()
def __init__ ( self , y , X = None , instance_indexes = None , query_type = 'AllLabels' , saving_path = None , * * kwargs ) : self . _index_len = None # check and record parameters self . _y = check_array ( y , ensure_2d = False , dtype = None ) if self . _y . ndim == 2 : if self . _y . shape [ 0 ] == 1 or self . _y . shape [ 1 ] == 1 : self . _y = self . _y . flatten ( ) ytype = type_of_target ( self . _y ) if len ( self . _y . shape ) == 2 : self . _target_type = 'multilabel' else : self . _target_type = ytype self . _index_len = len ( self . _y ) if len ( self . _y . shape ) == 1 : self . _label_space = unique_labels ( self . _y ) elif len ( self . _y . shape ) == 2 : self . _label_space = list ( range ( self . _y . shape [ 1 ] ) ) else : raise ValueError ( "Label matrix should be 1d or 2d array." ) self . _label_num = len ( self . _label_space ) self . _instance_flag = False if X is not None : self . _instance_flag = True self . _X = check_array ( X , accept_sparse = 'csr' , ensure_2d = True , order = 'C' ) n_samples = self . _X . shape [ 0 ] if n_samples != self . _index_len : raise ValueError ( "Different length of instances and labels found." ) else : self . _index_len = n_samples if instance_indexes is None : self . _indexes = [ i for i in range ( self . _index_len ) ] else : if len ( instance_indexes ) != self . _index_len : raise ValueError ( "Length of given instance_indexes do not accord the data set." ) self . _indexes = copy . copy ( instance_indexes ) if check_query_type ( query_type ) : self . query_type = query_type if self . query_type == 'Features' and not self . _instance_flag : raise Exception ( "In feature querying, feature matrix must be given." ) else : raise NotImplementedError ( "Query type %s is not implemented." % type ) self . _split = False train_idx = kwargs . pop ( 'train_idx' , None ) test_idx = kwargs . pop ( 'test_idx' , None ) label_idx = kwargs . pop ( 'label_idx' , None ) unlabel_idx = kwargs . pop ( 'unlabel_idx' , None ) if train_idx is not None and test_idx is not None and label_idx is not None and unlabel_idx is not None : if not ( len ( train_idx ) == len ( test_idx ) == len ( label_idx ) == len ( unlabel_idx ) ) : raise ValueError ( "train_idx, test_idx, label_idx, unlabel_idx " "should have the same split count (length)" ) self . _split = True self . train_idx = train_idx self . test_idx = test_idx self . label_idx = label_idx self . unlabel_idx = unlabel_idx self . split_count = len ( train_idx ) self . _saving_path = saving_path self . _saving_dir = None if saving_path is not None : if not isinstance ( self . _saving_path , str ) : raise TypeError ( "A string is expected, but received: %s" % str ( type ( self . _saving_path ) ) ) self . _saving_path = os . path . abspath ( saving_path ) if os . path . isdir ( self . _saving_path ) : self . _saving_dir = self . _saving_path if os . path . exists ( os . path . join ( saving_path , 'al_settings.pkl' ) ) : warnings . warn ( "An existed Toolbox file is detected, load the existed one in case of overwriting. " "(Delete the old file to create a new Toolbox object)" , category = UserWarning ) with open ( os . path . join ( saving_path , 'al_settings.pkl' ) , 'rb' ) as f : existed_toolbox = pickle . load ( f ) for ke in existed_toolbox . __dict__ . keys ( ) : setattr ( self , ke , getattr ( existed_toolbox , ke ) ) return else : self . _saving_dir = os . path . split ( self . _saving_path ) [ 0 ] # if a directory, a dir and None will return. if os . path . exists ( saving_path ) : with open ( os . path . abspath ( saving_path ) , 'rb' ) as f : existed_toolbox = pickle . load ( f ) for ke in existed_toolbox . __dict__ . keys ( ) : setattr ( self , ke , getattr ( existed_toolbox , ke ) ) return self . save ( )