(self, X, y=None)
return X_transform
Transform X with the encoding and scaling requirements set by fit().
        This function will perform One Hot Encoding, Feature Hashing and Scaling on X.
        Returns X_transform as a numpy array or a pandas dataframe based on return_type set in constructor.
Transform X with the encoding and scaling requirements set by fit().
        This function will perform One Hot Encoding, Feature Hashing and Scaling on X.
        Returns X_transform as a numpy array or a pandas dataframe based on return_type set in constructor.
Transform X with the encoding and scaling requirements set by fit () . This function will perform One Hot Encoding Feature Hashing and Scaling on X . Returns X_transform as a numpy array or a pandas dataframe based on return_type set in constructor .
def transform(self, X, y=None):
        """
        Transform X with the encoding and scaling requirements set by fit().
        This function will perform One Hot Encoding, Feature Hashing and Scaling on X.
        Returns X_transform as a numpy array or a pandas dataframe based on return_type set in constructor.
        """        
        
        X_transform = None
        scale_df = pd.DataFrame() # Initialize as empty Data Frame for convenience of concat operations below
        ohe_df = None
        hash_df = None
        cv_df = None
        tfidf_df = None
        text_df = None
        
        if self.ohe:
            # Get a subset of the data that requires one hot encoding
            ohe_df = X[self.ohe_meta.index.tolist()]

            # Apply one hot encoding to relevant columns
            ohe_df = pd.get_dummies(ohe_df, columns=ohe_df.columns)

            # Align the columns with the original dataset. 
            # This is to prevent different number or order of features between training and test datasets.
            ohe_df = ohe_df.align(self.ohe_df_structure, join='right', axis=1)[0]

            # Fill missing values in the OHE dataframe, that may appear after alignment, with zeros.
            ohe_df = utils.fillna(ohe_df, method="zeros")
            
            # Add the encoded columns to the result dataset
            X_transform = ohe_df

        if self.hash:
            # Get a subset of the data that requires feature hashing
            hash_df = X[self.hash_meta.index.tolist()]
            hash_cols = hash_df.columns

            # Hash unique values for each relevant column and then join to a dataframe for hashed data
            for c in hash_cols:
                unique = self.hasher(hash_df, c, self.hash_meta["strategy_args"].loc[c])
                hash_df = hash_df.join(unique, on=c)
                hash_df = hash_df.drop(c, axis=1)
                # Fill any missing values in the hash dataframe
                hash_df = utils.fillna(hash_df, method="zeros")
        
        if self.cv:
            # Get a subset of the data that requires count vectorizing
            cv_df = X[self.cv_meta.index.tolist()]
            cv_cols = cv_df.columns

            # Get count vectors for each relevant column and then join to a dataframe for count vectorized data
            for c in cv_cols:
                unique = self.text_vectorizer(cv_df, c, type="count", **self.cv_meta["strategy_args"].loc[c])
                cv_df = cv_df.join(unique, on=c)
                cv_df = cv_df.drop(c, axis=1)

            # Align the columns with the original dataset. 
            # This is to prevent different number or order of features between training and test datasets.
            cv_df = cv_df.align(self.cv_df_structure, join='right', axis=1)[0]

            # Fill missing values in the dataframe that may appear after alignment with zeros.
            cv_df = utils.fillna(cv_df, method="zeros")

        if self.tfidf:
            # Get a subset of the data that requires tfidf vectorizing
            tfidf_df = X[self.tfidf_meta.index.tolist()]
            tfidf_cols = tfidf_df.columns

            # Get tfidf vectors for each relevant column and then join to a dataframe for tfidf vectorized data
            for c in tfidf_cols:
                unique = self.text_vectorizer(tfidf_df, c, type="tfidf", **self.tfidf_meta["strategy_args"].loc[c])
                tfidf_df = tfidf_df.join(unique, on=c)
                tfidf_df = tfidf_df.drop(c, axis=1)

            # Align the columns with the original dataset. 
            # This is to prevent different number or order of features between training and test datasets.
            tfidf_df = tfidf_df.align(self.tfidf_df_structure, join='right', axis=1)[0]

            # Fill missing values in the dataframe that may appear after alignment with zeros.
            tfidf_df = utils.fillna(tfidf_df, method="zeros")
        
        if self.text:
            # Get a subset of the data that requires text similarity OHE
            text_df = X[self.text_meta.index.tolist()]
            text_cols = text_df.columns

            # Get text similarity OHE for each relevant column and then join to a dataframe for text similarity OHE data
            for c in text_cols:
                unique = self.text_similarity(text_df, c)
                text_df = text_df.join(unique, on=c)
                text_df = text_df.drop(c, axis=1)

            # Align the columns with the original dataset. 
            # This is to prevent different number or order of features between training and test datasets.
            text_df = text_df.align(self.text_df_structure, join='right', axis=1)[0]

            # Fill missing values in the dataframe that may appear after alignment with zeros.
            text_df = utils.fillna(text_df, method="zeros")

            # Add the text similary OHE data to the result dataset
            if X_transform is None:
                X_transform = text_df
            else:
                X_transform = pd.concat([X_transform, text_df], join='outer', axis=1, sort=False)

        if self.scale:
            # Get a subset of the data that requires scaling
            scale_df = X[self.scale_meta.index.tolist()]

        # If scale_hashed = True join the hashed columns to the scaling dataframe
        if self.hash and self.scale_hashed:
            if self.scale:
                scale_df = pd.concat([scale_df, hash_df], join='outer', axis=1, sort=False)
            else:
                scale_df = hash_df
                # If only hashed columns are being scaled, the scaler needs to be instantiated
                self.scaler_instance = utils.get_scaler(scale_df, missing=self.missing, scaler=self.scaler, **self.kwargs)
        elif self.hash:
            # Add the hashed columns to the result dataset
            if X_transform is None:
                X_transform = hash_df
            else:
                X_transform = pd.concat([X_transform, hash_df], join='outer', axis=1, sort=False)

        # If scale_vectors = True join the count vectorized columns to the scaling dataframe
        if self.cv and self.scale_vectors:
            if self.scale or (self.hash and self.scale_hashed):
                scale_df = pd.concat([scale_df, cv_df], join='outer', axis=1, sort=False)
            else:
                scale_df = cv_df
                # If only count vectorized columns are being scaled, the scaler needs to be instantiated
                self.scaler_instance = utils.get_scaler(scale_df, missing=self.missing, scaler=self.scaler, **self.kwargs)
        elif self.cv:
            # Add the count vectorized columns to the result dataset
            if X_transform is None:
                X_transform = cv_df
            else:
                X_transform = pd.concat([X_transform, cv_df], join='outer', axis=1, sort=False)

        # If scale_vectors = True join the tfidf vectorized columns to the scaling dataframe
        if self.tfidf and self.scale_vectors:
            if self.scale or (self.hash and self.scale_hashed) or self.cv:
                scale_df = pd.concat([scale_df, tfidf_df], join='outer', axis=1, sort=False)
            else:
                scale_df = tfidf_df
                # If only tfidf vectorized columns are being scaled, the scaler needs to be instantiated
                self.scaler_instance = utils.get_scaler(scale_df, missing=self.missing, scaler=self.scaler, **self.kwargs)
        elif self.tfidf:
            # Add the count vectorized columns to the result dataset
            if X_transform is None:
                X_transform = tfidf_df
            else:
                X_transform = pd.concat([X_transform, tfidf_df], join='outer', axis=1, sort=False)

        try:
            # Perform scaling on the relevant data
            if len(scale_df) > 0:
                # Align the columns with the original dataset. 
                # This is to prevent different number or order of features between training and test datasets.
                scale_df = scale_df.align(self.scale_df_structure, join='right', axis=1)[0]
                
                scale_df = utils.fillna(scale_df, method=self.missing)

                scale_df = pd.DataFrame(self.scaler_instance.transform(scale_df), index=scale_df.index, columns=scale_df.columns)
                
                # Add the scaled columns to the result dataset
                if X_transform is None:
                    X_transform = scale_df
                else:
                    X_transform = pd.concat([X_transform, scale_df], join='outer', axis=1, sort=False)
        except AttributeError:
            pass

        if self.no_prep:
            # Get a subset of the data that doesn't require preprocessing
            no_prep_df = X[self.none_meta.index.tolist()]
            # Fill any missing values in the no prep dataframe
            no_prep_df = utils.fillna(no_prep_df, method="zeros")
        
            # Finally join the columns that do not require preprocessing to the result dataset
            if X_transform is None:
                X_transform = no_prep_df
            else:
                X_transform = pd.concat([X_transform, no_prep_df], join='outer', axis=1, sort=False)
        
        # Output information to the terminal and log file if required
        if self.log is not None:
            self._print_log(3, ohe_df=ohe_df, scale_df=scale_df, hash_df=hash_df, cv_df=cv_df, tfidf_df=tfidf_df, text_df=text_df, X_transform=X_transform)

        if self.return_type == 'np':
            return X_transform.values
        
        return X_transform
def transform ( self , X , y = None ) : X_transform = None scale_df = pd . DataFrame ( ) # Initialize as empty Data Frame for convenience of concat operations below ohe_df = None hash_df = None cv_df = None tfidf_df = None text_df = None if self . ohe : # Get a subset of the data that requires one hot encoding ohe_df = X [ self . ohe_meta . index . tolist ( ) ] # Apply one hot encoding to relevant columns ohe_df = pd . get_dummies ( ohe_df , columns = ohe_df . columns ) # Align the columns with the original dataset.  # This is to prevent different number or order of features between training and test datasets. ohe_df = ohe_df . align ( self . ohe_df_structure , join = 'right' , axis = 1 ) [ 0 ] # Fill missing values in the OHE dataframe, that may appear after alignment, with zeros. ohe_df = utils . fillna ( ohe_df , method = "zeros" ) # Add the encoded columns to the result dataset X_transform = ohe_df if self . hash : # Get a subset of the data that requires feature hashing hash_df = X [ self . hash_meta . index . tolist ( ) ] hash_cols = hash_df . columns # Hash unique values for each relevant column and then join to a dataframe for hashed data for c in hash_cols : unique = self . hasher ( hash_df , c , self . hash_meta [ "strategy_args" ] . loc [ c ] ) hash_df = hash_df . join ( unique , on = c ) hash_df = hash_df . drop ( c , axis = 1 ) # Fill any missing values in the hash dataframe hash_df = utils . fillna ( hash_df , method = "zeros" ) if self . cv : # Get a subset of the data that requires count vectorizing cv_df = X [ self . cv_meta . index . tolist ( ) ] cv_cols = cv_df . columns # Get count vectors for each relevant column and then join to a dataframe for count vectorized data for c in cv_cols : unique = self . text_vectorizer ( cv_df , c , type = "count" , * * self . cv_meta [ "strategy_args" ] . loc [ c ] ) cv_df = cv_df . join ( unique , on = c ) cv_df = cv_df . drop ( c , axis = 1 ) # Align the columns with the original dataset.  # This is to prevent different number or order of features between training and test datasets. cv_df = cv_df . align ( self . cv_df_structure , join = 'right' , axis = 1 ) [ 0 ] # Fill missing values in the dataframe that may appear after alignment with zeros. cv_df = utils . fillna ( cv_df , method = "zeros" ) if self . tfidf : # Get a subset of the data that requires tfidf vectorizing tfidf_df = X [ self . tfidf_meta . index . tolist ( ) ] tfidf_cols = tfidf_df . columns # Get tfidf vectors for each relevant column and then join to a dataframe for tfidf vectorized data for c in tfidf_cols : unique = self . text_vectorizer ( tfidf_df , c , type = "tfidf" , * * self . tfidf_meta [ "strategy_args" ] . loc [ c ] ) tfidf_df = tfidf_df . join ( unique , on = c ) tfidf_df = tfidf_df . drop ( c , axis = 1 ) # Align the columns with the original dataset.  # This is to prevent different number or order of features between training and test datasets. tfidf_df = tfidf_df . align ( self . tfidf_df_structure , join = 'right' , axis = 1 ) [ 0 ] # Fill missing values in the dataframe that may appear after alignment with zeros. tfidf_df = utils . fillna ( tfidf_df , method = "zeros" ) if self . text : # Get a subset of the data that requires text similarity OHE text_df = X [ self . text_meta . index . tolist ( ) ] text_cols = text_df . columns # Get text similarity OHE for each relevant column and then join to a dataframe for text similarity OHE data for c in text_cols : unique = self . text_similarity ( text_df , c ) text_df = text_df . join ( unique , on = c ) text_df = text_df . drop ( c , axis = 1 ) # Align the columns with the original dataset.  # This is to prevent different number or order of features between training and test datasets. text_df = text_df . align ( self . text_df_structure , join = 'right' , axis = 1 ) [ 0 ] # Fill missing values in the dataframe that may appear after alignment with zeros. text_df = utils . fillna ( text_df , method = "zeros" ) # Add the text similary OHE data to the result dataset if X_transform is None : X_transform = text_df else : X_transform = pd . concat ( [ X_transform , text_df ] , join = 'outer' , axis = 1 , sort = False ) if self . scale : # Get a subset of the data that requires scaling scale_df = X [ self . scale_meta . index . tolist ( ) ] # If scale_hashed = True join the hashed columns to the scaling dataframe if self . hash and self . scale_hashed : if self . scale : scale_df = pd . concat ( [ scale_df , hash_df ] , join = 'outer' , axis = 1 , sort = False ) else : scale_df = hash_df # If only hashed columns are being scaled, the scaler needs to be instantiated self . scaler_instance = utils . get_scaler ( scale_df , missing = self . missing , scaler = self . scaler , * * self . kwargs ) elif self . hash : # Add the hashed columns to the result dataset if X_transform is None : X_transform = hash_df else : X_transform = pd . concat ( [ X_transform , hash_df ] , join = 'outer' , axis = 1 , sort = False ) # If scale_vectors = True join the count vectorized columns to the scaling dataframe if self . cv and self . scale_vectors : if self . scale or ( self . hash and self . scale_hashed ) : scale_df = pd . concat ( [ scale_df , cv_df ] , join = 'outer' , axis = 1 , sort = False ) else : scale_df = cv_df # If only count vectorized columns are being scaled, the scaler needs to be instantiated self . scaler_instance = utils . get_scaler ( scale_df , missing = self . missing , scaler = self . scaler , * * self . kwargs ) elif self . cv : # Add the count vectorized columns to the result dataset if X_transform is None : X_transform = cv_df else : X_transform = pd . concat ( [ X_transform , cv_df ] , join = 'outer' , axis = 1 , sort = False ) # If scale_vectors = True join the tfidf vectorized columns to the scaling dataframe if self . tfidf and self . scale_vectors : if self . scale or ( self . hash and self . scale_hashed ) or self . cv : scale_df = pd . concat ( [ scale_df , tfidf_df ] , join = 'outer' , axis = 1 , sort = False ) else : scale_df = tfidf_df # If only tfidf vectorized columns are being scaled, the scaler needs to be instantiated self . scaler_instance = utils . get_scaler ( scale_df , missing = self . missing , scaler = self . scaler , * * self . kwargs ) elif self . tfidf : # Add the count vectorized columns to the result dataset if X_transform is None : X_transform = tfidf_df else : X_transform = pd . concat ( [ X_transform , tfidf_df ] , join = 'outer' , axis = 1 , sort = False ) try : # Perform scaling on the relevant data if len ( scale_df ) > 0 : # Align the columns with the original dataset.  # This is to prevent different number or order of features between training and test datasets. scale_df = scale_df . align ( self . scale_df_structure , join = 'right' , axis = 1 ) [ 0 ] scale_df = utils . fillna ( scale_df , method = self . missing ) scale_df = pd . DataFrame ( self . scaler_instance . transform ( scale_df ) , index = scale_df . index , columns = scale_df . columns ) # Add the scaled columns to the result dataset if X_transform is None : X_transform = scale_df else : X_transform = pd . concat ( [ X_transform , scale_df ] , join = 'outer' , axis = 1 , sort = False ) except AttributeError : pass if self . no_prep : # Get a subset of the data that doesn't require preprocessing no_prep_df = X [ self . none_meta . index . tolist ( ) ] # Fill any missing values in the no prep dataframe no_prep_df = utils . fillna ( no_prep_df , method = "zeros" ) # Finally join the columns that do not require preprocessing to the result dataset if X_transform is None : X_transform = no_prep_df else : X_transform = pd . concat ( [ X_transform , no_prep_df ] , join = 'outer' , axis = 1 , sort = False ) # Output information to the terminal and log file if required if self . log is not None : self . _print_log ( 3 , ohe_df = ohe_df , scale_df = scale_df , hash_df = hash_df , cv_df = cv_df , tfidf_df = tfidf_df , text_df = text_df , X_transform = X_transform ) if self . return_type == 'np' : return X_transform . values return X_transform