(self, load_script=False, variant="predict")
Return a prediction by applying an existing model to the supplied data.
        If variant='predict_proba', return the predicted probabilties for each sample. Only applicable for certain classes.
        If variant='predict_log_proba', return the log probabilities for each sample. Only applicable for certain classes.
        This method can be called from a chart expression or the load script in Qlik.
        The load_script flag needs to be set accordingly for the correct response.
Return a prediction by applying an existing model to the supplied data.
        If variant='predict_proba', return the predicted probabilties for each sample. Only applicable for certain classes.
        If variant='predict_log_proba', return the log probabilities for each sample. Only applicable for certain classes.
        This method can be called from a chart expression or the load script in Qlik.
        The load_script flag needs to be set accordingly for the correct response.
Return a prediction by applying an existing model to the supplied data . If variant = predict_proba return the predicted probabilties for each sample . Only applicable for certain classes . If variant = predict_log_proba return the log probabilities for each sample . Only applicable for certain classes . This method can be called from a chart expression or the load script in Qlik . The load_script flag needs to be set accordingly for the correct response .
def predict(self, load_script=False, variant="predict"):
        """
        Return a prediction by applying an existing model to the supplied data.
        If variant='predict_proba', return the predicted probabilties for each sample. Only applicable for certain classes.
        If variant='predict_log_proba', return the log probabilities for each sample. Only applicable for certain classes.
        This method can be called from a chart expression or the load script in Qlik.
        The load_script flag needs to be set accordingly for the correct response.
        """
        
        # Interpret the request data based on the expected row and column structure
        row_template = ['strData', 'strData']
        col_headers = ['model_name', 'n_features']
        feature_col_num = 1
        
        # An additional key field column is expected if the call is made through the load script
        if load_script:
            row_template = ['strData', 'strData', 'strData']
            col_headers = ['model_name', 'key', 'n_features']
            feature_col_num = 2
        
        # Create a Pandas Data Frame for the request data
        self.request_df = utils.request_df(self.request, row_template, col_headers)
               
        # Initialize the persistent model
        self.model = PersistentModel()
        
        # Get the model name from the request dataframe
        self.model.name = self.request_df.loc[0, 'model_name']
        
        # Get the model from cache or disk
        self._get_model()
        
        # Debug information is printed to the terminal and logs if the paramater debug = true
        if self.model.debug:
            self._print_log(3)
        
        if load_script:
            # Set the key column as the index
            self.request_df.set_index("key", drop=False, inplace=True)
        
        try:
            # Split the features provided as a string into individual columns
            self.X = pd.DataFrame([x[feature_col_num].split("|") for x in self.request_df.values.tolist()],\
                                        columns=self.model.features_df.loc[:,"name"].tolist(),\
                                        index=self.request_df.index)
        except AssertionError as ae:
            err = "The number of input columns do not match feature definitions. Ensure you are using the | delimiter and that the target is not included in your input to the prediction function."
            raise AssertionError(err) from ae
        
        # Convert the data types based on feature definitions 
        self.X = utils.convert_types(self.X, self.model.features_df, sort=False)

        if variant in ('predict_proba', 'predict_log_proba'):
            # If probabilities need to be returned
            if variant == 'predict_proba':
                # Get the predicted probability for each sample 
                self.y = self.model.pipe.predict_proba(self.X)
            elif variant == 'predict_log_proba':
                # Get the log probability for each sample
                self.y = self.model.pipe.predict_log_proba(self.X)
                
            # Prepare a list of probability by class for each sample
            probabilities = []

            for a in self.y:
                s = ""
                i = 0
                for b in a:
                    s = s + ", {0}: {1:.3f}".format(self.model.pipe.named_steps['estimator'].classes_[i], b)
                    i = i + 1
                probabilities.append(s[2:])
            
            self.y = probabilities
                
        else:
            # Predict y for X using the previously fit pipeline
            self.y = self.model.pipe.predict(self.X)

            # Inverse transformations on the targets if required
            if self.model.scale_target or self.model.make_stationary:
                # Apply the transformer to the test targets
                self.y = self.model.target_transformer.inverse_transform(self.y) 

        # Prepare the response
        self.response = pd.DataFrame(self.y, columns=["result"], index=self.X.index)
        
        if load_script:
            # Add the key field column to the response
            self.response = self.request_df.join(self.response).drop(['n_features'], axis=1)
        
            # If the function was called through the load script we return a Data Frame
            self._send_table_description("predict")
            
            # Debug information is printed to the terminal and logs if the paramater debug = true
            if self.model.debug:
                self._print_log(4)
            
            return self.response
            
        # If the function was called through a chart expression we return a Series
        else:
            # Debug information is printed to the terminal and logs if the paramater debug = true
            if self.model.debug:
                self._print_log(4)
            
            return self.response.loc[:,'result']
def predict ( self , load_script = False , variant = "predict" ) : # Interpret the request data based on the expected row and column structure row_template = [ 'strData' , 'strData' ] col_headers = [ 'model_name' , 'n_features' ] feature_col_num = 1 # An additional key field column is expected if the call is made through the load script if load_script : row_template = [ 'strData' , 'strData' , 'strData' ] col_headers = [ 'model_name' , 'key' , 'n_features' ] feature_col_num = 2 # Create a Pandas Data Frame for the request data self . request_df = utils . request_df ( self . request , row_template , col_headers ) # Initialize the persistent model self . model = PersistentModel ( ) # Get the model name from the request dataframe self . model . name = self . request_df . loc [ 0 , 'model_name' ] # Get the model from cache or disk self . _get_model ( ) # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 3 ) if load_script : # Set the key column as the index self . request_df . set_index ( "key" , drop = False , inplace = True ) try : # Split the features provided as a string into individual columns self . X = pd . DataFrame ( [ x [ feature_col_num ] . split ( "|" ) for x in self . request_df . values . tolist ( ) ] , columns = self . model . features_df . loc [ : , "name" ] . tolist ( ) , index = self . request_df . index ) except AssertionError as ae : err = "The number of input columns do not match feature definitions. Ensure you are using the | delimiter and that the target is not included in your input to the prediction function." raise AssertionError ( err ) from ae # Convert the data types based on feature definitions  self . X = utils . convert_types ( self . X , self . model . features_df , sort = False ) if variant in ( 'predict_proba' , 'predict_log_proba' ) : # If probabilities need to be returned if variant == 'predict_proba' : # Get the predicted probability for each sample  self . y = self . model . pipe . predict_proba ( self . X ) elif variant == 'predict_log_proba' : # Get the log probability for each sample self . y = self . model . pipe . predict_log_proba ( self . X ) # Prepare a list of probability by class for each sample probabilities = [ ] for a in self . y : s = "" i = 0 for b in a : s = s + ", {0}: {1:.3f}" . format ( self . model . pipe . named_steps [ 'estimator' ] . classes_ [ i ] , b ) i = i + 1 probabilities . append ( s [ 2 : ] ) self . y = probabilities else : # Predict y for X using the previously fit pipeline self . y = self . model . pipe . predict ( self . X ) # Inverse transformations on the targets if required if self . model . scale_target or self . model . make_stationary : # Apply the transformer to the test targets self . y = self . model . target_transformer . inverse_transform ( self . y ) # Prepare the response self . response = pd . DataFrame ( self . y , columns = [ "result" ] , index = self . X . index ) if load_script : # Add the key field column to the response self . response = self . request_df . join ( self . response ) . drop ( [ 'n_features' ] , axis = 1 ) # If the function was called through the load script we return a Data Frame self . _send_table_description ( "predict" ) # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 4 ) return self . response # If the function was called through a chart expression we return a Series else : # Debug information is printed to the terminal and logs if the paramater debug = true if self . model . debug : self . _print_log ( 4 ) return self . response . loc [ : , 'result' ]