build/lib/AutoMxL/Preprocessing/Categorical.py
def transform(self, df, verbose=False):
        """ transform dataset categorical features using the encoder.
        Can be done only if encoder has been fitted

        Parameters
        ----------
        df : DataFrame
            dataset to transform
        verbose : boolean (Default False)
            Get logging information

        Returns
        -------
        DataFrame : modified dataset
        """
        assert self.is_fitted, 'fit the encoding first using .fit method'

        df_local = df.copy()

        # if list of features to encode is not empty
        if len(self.l_var2encode) > 0:
            # one hot encoding method
            if self.method == 'one_hot':

                return dummy_all_var(df_local, var_list=self.l_var2encode, prefix_list=None, keep=False,
                                     verbose=verbose)

            # Deep learning embedding method
            elif self.method == 'deep_encoder':
                # features not to encode
                self.l_var_other = [col for col in df_local.columns.tolist() if col not in self.l_var2encode]

                # transform data with int encoder
                for col in self.l_var2encode:
                    df_local[col] = self.d_int_encoders[col].fit_transform(df_local[col].astype('str'))

                # get embedding
                if verbose:
                    print(' Deep Encoder Embedding dim:')

                df_embedded = df_local[self.l_var2encode].copy()

                for col, d_level in self.d_embeddings.items():
                    for i in range(len(d_level[0])):
                        # replace int values with new embedding
                        df_embedded[col + '_' + str(i)] = df_embedded[col].replace(
                            {k: v[i] for k, v in d_level.items()})

                    # drop raw feature
                    df_embedded = df_embedded.drop(col, axis=1)

                    # verbose
                    if verbose:
                        print("  > " + col + ":", len(d_level[0]))

                return pd.concat([df[self.l_var_other], df_embedded], axis=1)

        # if no feature to encode
        else:
            print(" No variable to encode")

            return df_local
 transform dataset categorical features using the encoder.
        Can be done only if encoder has been fitted

        Parameters
        ----------
        df : DataFrame
            dataset to transform
        verbose : boolean (Default False)
            Get logging information

        Returns
        -------
        DataFrame : modified dataset
        
transform dataset categorical features using the encoder.
Can be done only if encoder has been fitted

Parameters

df : DataFrame
dataset to transform
verbose : boolean (Default False)
Get logging information

Returns

DataFrame : modified dataset
transform dataset categorical features using the encoder . Can be done only if encoder has been fitted Parameters df : DataFrame dataset to transform verbose : boolean ( Default False ) Get logging information Returns DataFrame : modified dataset
def transform(self, df, verbose=False):
        assert self.is_fitted, 'fit the encoding first using .fit method'
        df_local = df.copy()
        if len(self.l_var2encode) > 0:
            if self.method == 'one_hot':
                return dummy_all_var(df_local, var_list=self.l_var2encode, prefix_list=None, keep=False,
                                     verbose=verbose)
            elif self.method == 'deep_encoder':
                self.l_var_other = [col for col in df_local.columns.tolist() if col not in self.l_var2encode]
                for col in self.l_var2encode:
                    df_local[col] = self.d_int_encoders[col].fit_transform(df_local[col].astype('str'))
                if verbose:
                    print(' Deep Encoder Embedding dim:')
                df_embedded = df_local[self.l_var2encode].copy()
                for col, d_level in self.d_embeddings.items():
                    for i in range(len(d_level[0])):
                        df_embedded[col + '_' + str(i)] = df_embedded[col].replace(
                            {k: v[i] for k, v in d_level.items()})
                    df_embedded = df_embedded.drop(col, axis=1)
                    if verbose:
                        print("  > " + col + ":", len(d_level[0]))
                return pd.concat([df[self.l_var_other], df_embedded], axis=1)
        else:
            print(" No variable to encode")
            return df_local
def transform ( self , df , verbose = False ) : assert self . is_fitted , 'fit the encoding first using .fit method' df_local = df . copy ( ) if len ( self . l_var2encode ) > 0 : if self . method == 'one_hot' : return dummy_all_var ( df_local , var_list = self . l_var2encode , prefix_list = None , keep = False , verbose = verbose ) elif self . method == 'deep_encoder' : self . l_var_other = [ col for col in df_local . columns . tolist ( ) if col not in self . l_var2encode ] for col in self . l_var2encode : df_local [ col ] = self . d_int_encoders [ col ] . fit_transform ( df_local [ col ] . astype ( 'str' ) ) if verbose : print ( ' Deep Encoder Embedding dim:' ) df_embedded = df_local [ self . l_var2encode ] . copy ( ) for col , d_level in self . d_embeddings . items ( ) : for i in range ( len ( d_level [ 0 ] ) ) : df_embedded [ col + '_' + str ( i ) ] = df_embedded [ col ] . replace ( { k : v [ i ] for k , v in d_level . items ( ) } ) df_embedded = df_embedded . drop ( col , axis = 1 ) if verbose : print ( "  > " + col + ":" , len ( d_level [ 0 ] ) ) return pd . concat ( [ df [ self . l_var_other ] , df_embedded ] , axis = 1 ) else : print ( " No variable to encode" ) return df_local
transform dataset categorical features using the encoder.
transform dataset categorical features using the encoder .
""" transform dataset categorical features using the encoder.
        Can be done only if encoder has been fitted

        Parameters
        ----------
        df : DataFrame
            dataset to transform
        verbose : boolean (Default False)
            Get logging information

        Returns
        -------
        DataFrame : modified dataset
        """ # if list of features to encode is not empty # one hot encoding method # Deep learning embedding method # features not to encode # transform data with int encoder # get embedding # replace int values with new embedding # drop raw feature # verbose # if no feature to encode
self
df
verbose