(self, X, y=None, features=None, retrain=False)
return self
Fit to the training dataset, storing information that will be needed for the transform dataset.
        Return the Preprocessor object.
        Optionally re-initizialise the object by passing retrain=True, and resending the features dataframe
Fit to the training dataset, storing information that will be needed for the transform dataset.
        Return the Preprocessor object.
        Optionally re-initizialise the object by passing retrain=True, and resending the features dataframe
Fit to the training dataset storing information that will be needed for the transform dataset . Return the Preprocessor object . Optionally re - initizialise the object by passing retrain = True and resending the features dataframe
def fit(self, X, y=None, features=None, retrain=False):
        """
        Fit to the training dataset, storing information that will be needed for the transform dataset.
        Return the Preprocessor object.
        Optionally re-initizialise the object by passing retrain=True, and resending the features dataframe
        """
        
        # Reinitialize this Preprocessor instance if required
        if retrain:
            if features is None:
                features = self.features
            
            self = self.__init__(features)
        
        # Get a subset of the data that requires one hot encoding
        self.ohe_df = X[self.ohe_meta.index.tolist()]
              
        # Apply one hot encoding to relevant columns
        self.ohe_df = pd.get_dummies(self.ohe_df, columns=self.ohe_df.columns)
        
        # Keep a copy of the OHE dataframe structure so we can align the transform dataset 
        self.ohe_df_structure = pd.DataFrame().reindex_like(self.ohe_df)
        
        # Scaling needs to be fit exclusively on the training data so as not to influence the results
        if self.scale:
            # Get a subset of the data that requires scaling
            self.scale_df = X[self.scale_meta.index.tolist()]
                   
        # If hashed columns need to be scaled, these need to be considered when setting up the scaler as well
        if self.hash and self.scale_hashed:
            # Get a subset of the data that requires feature hashing
            self.hash_df = X[self.hash_meta.index.tolist()]
            hash_cols = self.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(self.hash_df, c, self.hash_meta["hash_features"].loc[c])
                self.hash_df = self.hash_df.join(unique, on=c)
                self.hash_df = self.hash_df.drop(c, axis=1)
                
            if self.scale:
                self.scale_df = self.scale_df.join(self.hash_df)
            else:
                self.scale_df = self.hash_df 
        
        if len(self.scale_df) > 0:
            # Get an instance of the sklearn scaler fit to X
            self.scaler_instance = self.get_scaler(self.scale_df, missing=self.missing, scaler=self.scaler, **self.kwargs)
        
        return self
def fit ( self , X , y = None , features = None , retrain = False ) : # Reinitialize this Preprocessor instance if required if retrain : if features is None : features = self . features self = self . __init__ ( features ) # Get a subset of the data that requires one hot encoding self . ohe_df = X [ self . ohe_meta . index . tolist ( ) ] # Apply one hot encoding to relevant columns self . ohe_df = pd . get_dummies ( self . ohe_df , columns = self . ohe_df . columns ) # Keep a copy of the OHE dataframe structure so we can align the transform dataset  self . ohe_df_structure = pd . DataFrame ( ) . reindex_like ( self . ohe_df ) # Scaling needs to be fit exclusively on the training data so as not to influence the results if self . scale : # Get a subset of the data that requires scaling self . scale_df = X [ self . scale_meta . index . tolist ( ) ] # If hashed columns need to be scaled, these need to be considered when setting up the scaler as well if self . hash and self . scale_hashed : # Get a subset of the data that requires feature hashing self . hash_df = X [ self . hash_meta . index . tolist ( ) ] hash_cols = self . 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 ( self . hash_df , c , self . hash_meta [ "hash_features" ] . loc [ c ] ) self . hash_df = self . hash_df . join ( unique , on = c ) self . hash_df = self . hash_df . drop ( c , axis = 1 ) if self . scale : self . scale_df = self . scale_df . join ( self . hash_df ) else : self . scale_df = self . hash_df if len ( self . scale_df ) > 0 : # Get an instance of the sklearn scaler fit to X self . scaler_instance = self . get_scaler ( self . scale_df , missing = self . missing , scaler = self . scaler , * * self . kwargs ) return self