(self, X)
return y
Call a REST endpoint to get predictions from a model
Call a REST endpoint to get predictions from a model
Call a REST endpoint to get predictions from a model
def _get_rest_response(self, X):
        """
        Call a REST endpoint to get predictions from a model
        """

        predictions = []
        # Set nesting for the json payload if required
        payload_header = None if len(self.model['json'].keys()) == 0 else next(iter(self.model['json']))
        
        # Make a REST call for each sample
        for i in X.index:
            # Next the JSON payload if required
            self.model['json'] = dict(X.loc[i,:].astype("str").T) if payload_header is None else {payload_header: dict(X.loc[i,:].astype("str").T)}

            # Send the REST request and store parse the JSON response
            response = json.loads(requests.post(**self.model).text)
            # Add response for the current sample to a list
            predictions.append(response if self.response_section is None else response[self.response_section])

        # Convert responses to a dataframe
        predictions_df = pd.DataFrame(predictions).astype("str")
        
        # Return the required column from the response dataframe
        y = predictions_df.iloc[:,0].values if self.prediction_func == 'predict' else predictions_df[self.prediction_func].values
        return y
def _get_rest_response ( self , X ) : predictions = [ ] # Set nesting for the json payload if required payload_header = None if len ( self . model [ 'json' ] . keys ( ) ) == 0 else next ( iter ( self . model [ 'json' ] ) ) # Make a REST call for each sample for i in X . index : # Next the JSON payload if required self . model [ 'json' ] = dict ( X . loc [ i , : ] . astype ( "str" ) . T ) if payload_header is None else { payload_header : dict ( X . loc [ i , : ] . astype ( "str" ) . T ) } # Send the REST request and store parse the JSON response response = json . loads ( requests . post ( * * self . model ) . text ) # Add response for the current sample to a list predictions . append ( response if self . response_section is None else response [ self . response_section ] ) # Convert responses to a dataframe predictions_df = pd . DataFrame ( predictions ) . astype ( "str" ) # Return the required column from the response dataframe y = predictions_df . iloc [ : , 0 ] . values if self . prediction_func == 'predict' else predictions_df [ self . prediction_func ] . values return y