(self, load_script=False)
Return a prediction by using a pre-trained model.
        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 using a pre-trained model.
        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 using a pre - trained model . 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):
        """
        Return a prediction by using a pre-trained model.
        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', 'strData']
        col_headers = ['model_name', 'n_features', 'kwargs']
        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', 'strData']
            col_headers = ['model_name', 'key', 'n_features', 'kwargs']
            feature_col_num = 2

        # Interpret the request data based on the expected row and column structure
        self._initiate(row_template, col_headers)

        # Load the model
        self._get_model()

        # Prepare the input data
        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.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.features_df, sort=False)
        
        # Apply sorting if required
        if self.identifier is not None:
            self.X = self.X.sort_values(by=[self.identifier], ascending=True)

        # Drop sorting feature if required
        if self.exclude_identifier:
            self.X = self.X.drop(columns=[self.identifier])

        # Apply preprocessing if required
        X = self.X.copy() if self.prep is None else self.prep.transform(self.X.copy())

        # Generate predictions
        if self.is_rest_api:
            self.y = self._get_rest_response(X)
        else:
            self.y = getattr(self.model, self.prediction_func)(X)

        # The predictions may need to be decoded in case of classification labels
        # The labels can be passed as a dictionary through the SSE function's additional arguments using the 'labels' parameter
        if self.labels is not None:
            # Decode the predictions based on a dictionary of labels. The predictions are assumed to be integers
            self.y = utils.decode(self.y, self.labels)

        # Prepare the response, catering for multiple outputs per sample
        # Multiple predictions for the same sample are separated by the pipe, i.e; | delimiter
        if len(self.y.shape) > 1 and self.y.shape[1] == 2:
            self.response_df = pd.DataFrame(["|".join(item) for item in self.y.astype(str)], columns=["result"], index=self.X.index)
        else:
            self.response_df = pd.DataFrame(self.y, columns=["result"], index=self.X.index)

        if self.identifier is not None:
            # Reindex the response to reset to the original sort order
            self.response_df = self.response_df.reindex(self.request_df.index)

        if load_script:
            # Add the key field column to the response
            self.response_df = self.request_df.join(self.response_df).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.debug:
                self._print_log(4)
            
            return self.response_df
            
        # 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.debug:
                self._print_log(4)
            
            return self.response_df.loc[:,'result']
def predict ( self , load_script = False ) : # Interpret the request data based on the expected row and column structure row_template = [ 'strData' , 'strData' , 'strData' ] col_headers = [ 'model_name' , 'n_features' , 'kwargs' ] 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' , 'strData' ] col_headers = [ 'model_name' , 'key' , 'n_features' , 'kwargs' ] feature_col_num = 2 # Interpret the request data based on the expected row and column structure self . _initiate ( row_template , col_headers ) # Load the model self . _get_model ( ) # Prepare the input data 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 . 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 . features_df , sort = False ) # Apply sorting if required if self . identifier is not None : self . X = self . X . sort_values ( by = [ self . identifier ] , ascending = True ) # Drop sorting feature if required if self . exclude_identifier : self . X = self . X . drop ( columns = [ self . identifier ] ) # Apply preprocessing if required X = self . X . copy ( ) if self . prep is None else self . prep . transform ( self . X . copy ( ) ) # Generate predictions if self . is_rest_api : self . y = self . _get_rest_response ( X ) else : self . y = getattr ( self . model , self . prediction_func ) ( X ) # The predictions may need to be decoded in case of classification labels # The labels can be passed as a dictionary through the SSE function's additional arguments using the 'labels' parameter if self . labels is not None : # Decode the predictions based on a dictionary of labels. The predictions are assumed to be integers self . y = utils . decode ( self . y , self . labels ) # Prepare the response, catering for multiple outputs per sample # Multiple predictions for the same sample are separated by the pipe, i.e; | delimiter if len ( self . y . shape ) > 1 and self . y . shape [ 1 ] == 2 : self . response_df = pd . DataFrame ( [ "|" . join ( item ) for item in self . y . astype ( str ) ] , columns = [ "result" ] , index = self . X . index ) else : self . response_df = pd . DataFrame ( self . y , columns = [ "result" ] , index = self . X . index ) if self . identifier is not None : # Reindex the response to reset to the original sort order self . response_df = self . response_df . reindex ( self . request_df . index ) if load_script : # Add the key field column to the response self . response_df = self . request_df . join ( self . response_df ) . 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 . debug : self . _print_log ( 4 ) return self . response_df # 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 . debug : self . _print_log ( 4 ) return self . response_df . loc [ : , 'result' ]