Exemplo n.º 1
0
    def classify(self, model_id, data, production_model=False, batch_size=DEFAULT_BATCH_SIZE,
                 auto_batch=True, retry_if_throttled=True):
        validate_batch_size(batch_size)

        url = self.get_detail_url(model_id, action='classify')

        response = MonkeyLearnResponse()
        for i in range(0, len(data), batch_size):
            data_dict = self.remove_none_value({
                'data': data[i:i + batch_size],
                'production_model': production_model,
            })
            raw_response = self.make_request('POST', url, data_dict,
                                             retry_if_throttled=retry_if_throttled)
            response.add_raw_response(raw_response)

        return response
    def extract(self, model_id, data, production_model=False, batch_size=DEFAULT_BATCH_SIZE,
                retry_if_throttled=True, extra_args=None):
        if extra_args is None:
            extra_args = {}

        validate_batch_size(batch_size)

        url = self.get_detail_url(model_id, action='extract')

        response = MonkeyLearnResponse()
        for i in range(0, len(data), batch_size):
            data_dict = self.remove_none_value({
                'data': data[i:i + batch_size],
                'production_model': production_model,
            })
            data_dict.update(extra_args)
            raw_response = self.make_request('POST', url, data_dict,
                                             retry_if_throttled=retry_if_throttled)
            response.add_raw_response(raw_response)

        return response