def __init__(
            self,
            model,
            predict,
            input_validation=lambda data: (True, None),
            data_loader=json_numpy_loader,
            preprocessor=lambda x: x,
            postprocessor=make_serializable,
            to_numpy=True):
        """Initialize class with prediction function.

        Arguments:
            - predict (fn): function that takes a numpy array of features as input,
                and returns a prediction of targets
            - input_validation (fn): takes a numpy array as input;
                returns True if validation passes and False otherwise
            - data_loader (fn): reads flask request and returns data preprocessed to be
                used in the `predict` method
            - postprocessor (fn): transforms the predictions from the `predict` method
        """
        self.model = model
        self.predict = predict
        self.data_loader = data_loader
        self.preprocessor = preprocessor
        self.postprocessor = postprocessor
        self.app = Flask('{}_{}'.format(self.__class__.__name__, type(predict).__name__))
        self.api = Api(self.app, catch_all_404s=True)
        self._create_prediction_endpoint(
            data_loader=data_loader,
            input_validation=input_validation,
            preprocessor=preprocessor,
            postprocessor=postprocessor,
            to_numpy=to_numpy,
        )
        logger.info('Model predictions registered to endpoint /predictions (available via POST)')
        self.app.logger.setLevel(logger.level)  # TODO: separate configuration for API loglevel
        self._create_model_info_endpoint()
def __init__ ( self , model , predict , input_validation = lambda data : ( True , None ) , data_loader = json_numpy_loader , preprocessor = lambda x : x , postprocessor = make_serializable , to_numpy = True ) : self . model = model self . predict = predict self . data_loader = data_loader self . preprocessor = preprocessor self . postprocessor = postprocessor self . app = Flask ( '{}_{}' . format ( self . __class__ . __name__ , type ( predict ) . __name__ ) ) self . api = Api ( self . app , catch_all_404s = True ) self . _create_prediction_endpoint ( data_loader = data_loader , input_validation = input_validation , preprocessor = preprocessor , postprocessor = postprocessor , to_numpy = to_numpy , ) logger . info ( 'Model predictions registered to endpoint /predictions (available via POST)' ) self . app . logger . setLevel ( logger . level ) self . _create_model_info_endpoint ( )
Initialize class with prediction function.

        Arguments:
            - predict (fn): function that takes a numpy array of features as input,
                and returns a prediction of targets
            - input_validation (fn): takes a numpy array as input;
                returns True if validation passes and False otherwise
            - data_loader (fn): reads flask request and returns data preprocessed to be
                used in the `predict` method
            - postprocessor (fn): transforms the predictions from the `predict` method