def batch_predict()

in frauddetector/frauddetector.py [0:0]


    def batch_predict(self, timestamp, events=None, df=None, entity_id="unknown"):
        """Batch predict using your Amazon Forecast model

        Args:
            :timestamp:   A string indicating either the timestamp key or column
            :events:      A list of JSON events
            :df:          A Pandas DataFrame with your observations for prediction
            :entity_id:   The unique ID of your entity if known

        Returns:
            :predictions:   [{'credit_card_model_insightscore': 14.0, 'ruleResults': ['verify_outcome']}] list
        """
        if events is None and df is None:
            print("Please provide either a JSON object through events or a Pandas DataFrame through df!")
            return []
        predictions = []
        if type(events) == "dict":
            for event in events:
                event_timestamp = event[timestamp]
                tmp = event.pop(timestamp)
                predictions.append(
                    self.predict(
                        event_timestamp=event_timestamp,
                        event_variables=event,
                        entity_id=entity_id))
        else:
            try:
                events.loc[:, timestamp] = events.loc[:, timestamp].apply(lambda x: pd.to_datetime(x).strftime('%Y-%m-%dT%H:%M:%SZ'))
                for i in range(events.shape[0]):
                    event = json.loads(events.iloc[i, :].to_json())
                    for key in event:
                        event[key] = str(event[key])
                    event_timestamp = event[timestamp]
                    tmp = event.pop(timestamp)
                    predictions.append(
                        self.predict(
                            event_timestamp=event_timestamp,
                            event_variables=event,
                            entity_id=entity_id))
            except Exception as e:
                print("Warning: Make sure your input DataFrame complies with the service rules!")
                print(e)
        return predictions