(self, step, data=None)
Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required . : step : Print the corresponding step in the log
def _print_log(self, step, data=None):
        """
        Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
        """
        
        # Set mode to append to log file
        mode = 'a'

        if self.logfile is None:
            # Increment log counter for the class. Each instance of the class generates a new log.
            self.__class__.log_no += 1

            # Create a log file for the instance
            # Logs will be stored in ..\logs\SKLearn Log <n>.txt
            self.logfile = os.path.join(os.getcwd(), 'logs', 'SKLearn Log {}.txt'.format(self.log_no))
        
        if step == 1:
            # Output log header
            output = "\nSKLearnForQlik Log: {0} \n\n".format(time.ctime(time.time()))
            # Set mode to write new log file
            mode = 'w'
                
        elif step == 2:
            # Output the parameters
            output = "Model Name: {0}\n\n".format(self.model.name)
            output += "Execution arguments: {0}\n\n".format(self.exec_params)
            
            try:
                output += "Scaler: {0}, missing: {1}, scale_hashed: {2}, scale_vectors: {3}\n".format(\
                self.model.scaler, self.model.missing,self.model.scale_hashed, self.model.scale_vectors)
                output += "Scaler kwargs: {0}\n\n".format(self.model.scaler_kwargs)
            except AttributeError:
                output += "scale_hashed: {0}, scale_vectors: {1}\n".format(self.model.scale_hashed, self.model.scale_vectors)

            try:
                if self.model.dim_reduction:
                    output += "Reduction: {0}\nReduction kwargs: {1}\n\n".format(self.model.reduction, self.model.dim_reduction_args)
            except AttributeError:
                pass
            
            output += "Estimator: {0}\nEstimator kwargs: {1}\n\n".format(self.model.estimator, self.model.estimator_kwargs)
                
        elif step == 3:                    
            # Output the request dataframe
            output = "REQUEST: {0} rows x cols\nSample Data:\n\n".format(self.request_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.request_df.head().to_string(), self.request_df.tail().to_string())
        
        elif step == 4:
            # Output the response dataframe/series
            output = "RESPONSE: {0} rows x cols\nSample Data:\n\n".format(self.response.shape)
            output += "{0}\n...\n{1}\n\n".format(self.response.head().to_string(), self.response.tail().to_string())
                 
        elif step == 5:
            # Print the table description if the call was made from the load script
            output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n".format(self.table)
        
        elif step == 6:
            # Message when model is loaded from cache
            output = "\nModel {0} loaded from cache.\n\n".format(self.model.name)
            
        elif step == 7:
            # Message when model is loaded from disk
            output = "\nModel {0} loaded from disk.\n\n".format(self.model.name)
            
        elif step == 8:
            # Message when cache is updated
            output = "\nCache updated. Models in cache:\n{0}\n\n".format([k for k,v in self.__class__.model_cache.items()])
        
        elif step == 9:
            # Output when a parameter grid is set up
            output = "Model Name: {0}, Estimator: {1}\n\nGrid Search Arguments: {2}\n\nParameter Grid: {3}\n\n".\
            format(self.model.name, self.model.estimator, self.model.grid_search_args, self.model.param_grid)
        
        elif step == 10:
            # self.model.estimator_kwargs['architecture']
            output = "\nKeras architecture added to Model {0}:\n\n{1}\n\n".format(self.model.name,\
            self.model.architecture.to_string())

        elif step == 11:
            # Output after adding lag observations to input data
            output = "Lag observations added ({0} per sample). New input shape of X is {1}.\n\n".format(self.model.lags, data.shape)
            output += "Feature Definitions:\n{0}\n\n".format(self.model.features_df.to_string())
            output += "Sample Data:\n{0}\n...\n{1}\n\n".format(data.head(5).to_string(), data.tail(5).to_string())
                        
        sys.stdout.write(output)
        with open(self.logfile, mode, encoding='utf-8') as f:
            f.write(output)
def _print_log ( self , step , data = None ) : # Set mode to append to log file mode = 'a' if self . logfile is None : # Increment log counter for the class. Each instance of the class generates a new log. self . __class__ . log_no += 1 # Create a log file for the instance # Logs will be stored in ..\logs\SKLearn Log <n>.txt self . logfile = os . path . join ( os . getcwd ( ) , 'logs' , 'SKLearn Log {}.txt' . format ( self . log_no ) ) if step == 1 : # Output log header output = "\nSKLearnForQlik Log: {0} \n\n" . format ( time . ctime ( time . time ( ) ) ) # Set mode to write new log file mode = 'w' elif step == 2 : # Output the parameters output = "Model Name: {0}\n\n" . format ( self . model . name ) output += "Execution arguments: {0}\n\n" . format ( self . exec_params ) try : output += "Scaler: {0}, missing: {1}, scale_hashed: {2}, scale_vectors: {3}\n" . format ( self . model . scaler , self . model . missing , self . model . scale_hashed , self . model . scale_vectors ) output += "Scaler kwargs: {0}\n\n" . format ( self . model . scaler_kwargs ) except AttributeError : output += "scale_hashed: {0}, scale_vectors: {1}\n" . format ( self . model . scale_hashed , self . model . scale_vectors ) try : if self . model . dim_reduction : output += "Reduction: {0}\nReduction kwargs: {1}\n\n" . format ( self . model . reduction , self . model . dim_reduction_args ) except AttributeError : pass output += "Estimator: {0}\nEstimator kwargs: {1}\n\n" . format ( self . model . estimator , self . model . estimator_kwargs ) elif step == 3 : # Output the request dataframe output = "REQUEST: {0} rows x cols\nSample Data:\n\n" . format ( self . request_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . request_df . head ( ) . to_string ( ) , self . request_df . tail ( ) . to_string ( ) ) elif step == 4 : # Output the response dataframe/series output = "RESPONSE: {0} rows x cols\nSample Data:\n\n" . format ( self . response . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . response . head ( ) . to_string ( ) , self . response . tail ( ) . to_string ( ) ) elif step == 5 : # Print the table description if the call was made from the load script output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n" . format ( self . table ) elif step == 6 : # Message when model is loaded from cache output = "\nModel {0} loaded from cache.\n\n" . format ( self . model . name ) elif step == 7 : # Message when model is loaded from disk output = "\nModel {0} loaded from disk.\n\n" . format ( self . model . name ) elif step == 8 : # Message when cache is updated output = "\nCache updated. Models in cache:\n{0}\n\n" . format ( [ k for k , v in self . __class__ . model_cache . items ( ) ] ) elif step == 9 : # Output when a parameter grid is set up output = "Model Name: {0}, Estimator: {1}\n\nGrid Search Arguments: {2}\n\nParameter Grid: {3}\n\n" . format ( self . model . name , self . model . estimator , self . model . grid_search_args , self . model . param_grid ) elif step == 10 : # self.model.estimator_kwargs['architecture'] output = "\nKeras architecture added to Model {0}:\n\n{1}\n\n" . format ( self . model . name , self . model . architecture . to_string ( ) ) elif step == 11 : # Output after adding lag observations to input data output = "Lag observations added ({0} per sample). New input shape of X is {1}.\n\n" . format ( self . model . lags , data . shape ) output += "Feature Definitions:\n{0}\n\n" . format ( self . model . features_df . to_string ( ) ) output += "Sample Data:\n{0}\n...\n{1}\n\n" . format ( data . head ( 5 ) . to_string ( ) , data . tail ( 5 ) . to_string ( ) ) sys . stdout . write ( output ) with open ( self . logfile , mode , encoding = 'utf-8' ) as f : f . write ( output )