(self, data_inst, sample_ids=None)
Random sample method, a line's occur probability is decide by fraction
            support down sample and up sample
                if use down sample: should give a float ratio between [0, 1]
                otherwise: should give a float ratio larger than 1.0

        Parameters
        ----------
        data_inst : Table
            The input data

        sample_ids : None or list
            if None, will sample data from the class instance's parameters,
            otherwise, it will be sample transform process, which means use the samples_ids to generate data

        Returns
        -------
        new_data_inst: Table
            the output sample data, same format with input

        sample_ids: list, return only if sample_ids is None
Random sample method, a line's occur probability is decide by fraction
            support down sample and up sample
                if use down sample: should give a float ratio between [0, 1]
                otherwise: should give a float ratio larger than 1.0
Random sample method a line s occur probability is decide by fraction support down sample and up sample if use down sample : should give a float ratio between [ 0 1 ] otherwise : should give a float ratio larger than 1 . 0
def __sample(self, data_inst, sample_ids=None):
        """
        Random sample method, a line's occur probability is decide by fraction
            support down sample and up sample
                if use down sample: should give a float ratio between [0, 1]
                otherwise: should give a float ratio larger than 1.0

        Parameters
        ----------
        data_inst : Table
            The input data

        sample_ids : None or list
            if None, will sample data from the class instance's parameters,
            otherwise, it will be sample transform process, which means use the samples_ids to generate data

        Returns
        -------
        new_data_inst: Table
            the output sample data, same format with input

        sample_ids: list, return only if sample_ids is None


        """
        LOGGER.info("start to run random sampling")

        return_sample_ids = False
        if self.method == "downsample":
            if sample_ids is None:
                return_sample_ids = True
                idset = [key for key, value in data_inst.mapValues(lambda val: None).collect()]
                if self.fraction < 0 or self.fraction > 1:
                    raise ValueError("sapmle fractions should be a numeric number between 0 and 1inclusive")

                sample_num = max(1, int(self.fraction * len(idset)))

                sample_ids = resample(idset,
                                      replace=False,
                                      n_samples=sample_num,
                                      random_state=self.random_state)

            sample_dtable = session.parallelize(zip(sample_ids, range(len(sample_ids))),
                                                include_key=True,
                                                partition=data_inst.partitions)
            new_data_inst = data_inst.join(sample_dtable, lambda v1, v2: v1)

            callback(self.tracker, "random", [Metric("count", new_data_inst.count())], summary_dict=self._summary_buf)

            if return_sample_ids:
                return new_data_inst, sample_ids
            else:
                return new_data_inst

        elif self.method == "upsample":
            data_set = list(data_inst.collect())
            idset = [key for (key, value) in data_set]
            id_maps = dict(zip(idset, range(len(idset))))

            if sample_ids is None:
                return_sample_ids = True
                if self.fraction <= 0:
                    raise ValueError("sapmle fractions should be a numeric number large than 0")

                sample_num = int(self.fraction * len(idset))
                sample_ids = resample(idset,
                                      replace=True,
                                      n_samples=sample_num,
                                      random_state=self.random_state)

            new_data = []
            for i in range(len(sample_ids)):
                index = id_maps[sample_ids[i]]
                new_data.append((i, data_set[index][1]))

            new_data_inst = session.parallelize(new_data,
                                                include_key=True,
                                                partition=data_inst.partitions)

            callback(self.tracker, "random", [Metric("count", new_data_inst.count())], summary_dict=self._summary_buf)

            if return_sample_ids:
                return new_data_inst, sample_ids
            else:
                return new_data_inst

        else:
            raise ValueError("random sampler not support method {} yet".format(self.method))
def __sample ( self , data_inst , sample_ids = None ) : LOGGER . info ( "start to run random sampling" ) return_sample_ids = False if self . method == "downsample" : if sample_ids is None : return_sample_ids = True idset = [ key for key , value in data_inst . mapValues ( lambda val : None ) . collect ( ) ] if self . fraction < 0 or self . fraction > 1 : raise ValueError ( "sapmle fractions should be a numeric number between 0 and 1inclusive" ) sample_num = max ( 1 , int ( self . fraction * len ( idset ) ) ) sample_ids = resample ( idset , replace = False , n_samples = sample_num , random_state = self . random_state ) sample_dtable = session . parallelize ( zip ( sample_ids , range ( len ( sample_ids ) ) ) , include_key = True , partition = data_inst . partitions ) new_data_inst = data_inst . join ( sample_dtable , lambda v1 , v2 : v1 ) callback ( self . tracker , "random" , [ Metric ( "count" , new_data_inst . count ( ) ) ] , summary_dict = self . _summary_buf ) if return_sample_ids : return new_data_inst , sample_ids else : return new_data_inst elif self . method == "upsample" : data_set = list ( data_inst . collect ( ) ) idset = [ key for ( key , value ) in data_set ] id_maps = dict ( zip ( idset , range ( len ( idset ) ) ) ) if sample_ids is None : return_sample_ids = True if self . fraction <= 0 : raise ValueError ( "sapmle fractions should be a numeric number large than 0" ) sample_num = int ( self . fraction * len ( idset ) ) sample_ids = resample ( idset , replace = True , n_samples = sample_num , random_state = self . random_state ) new_data = [ ] for i in range ( len ( sample_ids ) ) : index = id_maps [ sample_ids [ i ] ] new_data . append ( ( i , data_set [ index ] [ 1 ] ) ) new_data_inst = session . parallelize ( new_data , include_key = True , partition = data_inst . partitions ) callback ( self . tracker , "random" , [ Metric ( "count" , new_data_inst . count ( ) ) ] , summary_dict = self . _summary_buf ) if return_sample_ids : return new_data_inst , sample_ids else : return new_data_inst else : raise ValueError ( "random sampler not support method {} yet" . format ( self . method ) )